A simple menu button implementation

zhaozj2021-02-16  41

Using a friend who has been 2000 knows that there is a button in the browsing interface of its basic information. After clicking, one and buttons will pop up a neat menu. It is very easy to make a similar control with Delphi, the code is as follows:

Unit menubtnvcl;

Interface

Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Buttons, CommCtrl, ExtCtrls, Menus

type TMenuBtn = class (TBitBtn) protected procedure DoEnter; override; procedure DoExit; override; {Protected declarations} public constructor Create (AOwner: TComponent); override; procedure Click; override; {Public declarations} published {AL:} {Published declarations } END;

PROCEDURE register;

IMPLEMENTATION

Procedure Register; Begin RegisterComponents ('Samples', [TMenubtn]); END;

constructor TMenuBtn.Create (AOwner: TComponent); begin inherited Create (AOwner); layout: = blGlyphRight; Font.Charset: = GB2312_CHARSET; Font.Color: = clWindowText; Font.Height: = -12; Font.Name: = ' Song; END;

Procedure tmenubtn.click; var tmp: tpoint; begin inherited click;

If Assigned (Popupmenu) THENU} TMP: = ClientToscreen (Point (0, Height); PopupMenu.Popup (tmp.x, tmp.y); end;

Procedure tmenubtn.doenter; begin font.style: = [fsbold]; inherited doenter;

Procedure tmenubtn.doexit; begin font.style: = []; inherited doexit;

End.

转载请注明原文地址:https://www.9cbs.com/read-27551.html

New Post(0)