菜单无法弹出,请教各位大虾!!!(100分)

8

8387815

Unregistered / Unconfirmed
GUEST, unregistred user!
//***********************************************************//
// 功能:在按钮按下时在它下方立即弹出菜单(用BitBtn可以) //
//***********************************************************//
unit UnitFlatMenuBtn;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, CommCtrl,
ExtCtrls,Menus,TFlatButtonUnit;

type
TFlatMenuBtn = class(TFlatButton)
{ 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', [TFlatMenuBtn]);
end;


constructor TFlatMenuBtn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
layout:=blGlyphRight;
Font.Charset := GB2312_CHARSET;
Font.Color := clWindowText;
Font.Height := -12;
Font.Name := '宋体';
end;

procedure TFlatMenuBtn.Click;
var tmp:TPoint;
begin
inherited Click;

if Assigned(PopUpMenu) then
begin
{ calc where to put menu }
tmp := ClientToScreen(Point(0, Height));
PopUpMenu.Popup(tmp.X, tmp.Y);
end;
end;


end.


 
忘了,是Delphi 5上的,TFlatButton是FLATSTYL控件里的
 
用getcursorpos(tmp);
PopUpMenu.Popup(tmp.X, tmp.Y);
试一下!
 
楼主,你这段代码在我的机器上没有问题啊!!!
只不过 PopupMenu 要设置,不能用父控件的。
 
To thx1180 还是不行阿,能否详细点? (我用TBitBtn+TPopupMenu是可以的,按下按钮时,菜单从它下方弹出)
 
var
Mp: TPoint;
begin
Mp:=FlatMenuBtn1.ClientToScreen(Point(0,0));
PopupMenu1.Popup(Mp.x,Mp.y+FlatMenuBtn1.Height+1);
end;
 
感谢 Yhhe,你提出方法可以做到,但我是想把它封装成VCL。
 
我将你的代码存为一个单元后注册组件,然后测试,如下:
拖一个TFlatMenuBtn 到窗体上,将其PopUpMenu设为一个弹出式菜单,运行即可。
在你那里是怎样的?
 
TO thx1180 是这样的阿 可是就是没菜单出现阿!!!
 
if Assigned(popupmenu) then
begin
tmp:=flatmenubtn.clientToscreen(point(0,height));
-----------
end;
 
找找别的原因吧。
比如放一个TFlatButton 到窗体上,再响应它的OnClick事件,看效果如何?
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
679
import
I
I
回复
0
查看
582
import
I
I
回复
0
查看
472
import
I
顶部