Blue
Red
Green
Orange
Voilet
Slate
Dark

如何实现在按钮的下方弹出PopupMenu或窗体?(50分)

  • 主题发起人 delphilai
  • 开始时间
D

delphilai

Unregistered / Unconfirmed
GUEST, unregistred user!
点击按钮,在按钮的坐下方弹出PopupMenu,关键就是要把按钮在窗体的坐标转换成屏幕坐标,
不要告诉我用ClientToScrean函数,当按钮属于某个容器的时它在窗体的坐标值会改变。
 

唐佐平

Unregistered / Unconfirmed
GUEST, unregistred user!
PopupMenu1.Popup(button1.Left,button1.Top);
 
D

delphilai

Unregistered / Unconfirmed
GUEST, unregistred user!
这我早就试过了,这样不行的,菜单会跑到上边去。
 
P

pink_wt

Unregistered / Unconfirmed
GUEST, unregistred user!
The GetCursorPos function retrieves the cursor's position,
in screen coordinates.

Syntax

BOOL GetCursorPos( LPPOINT lpPoint);
Parameters

lpPoint
[out] Pointer to a POINT structure that receives the screen coordinates of the cursor.
Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

你看行不行
 
P

p96114

Unregistered / Unconfirmed
GUEST, unregistred user!
可以使用TToolBar控件,在它上面增加一个按钮
这个按钮有一个属性叫DropDownMenu ,设为 PopupMenu即可
 
P

pink_wt

Unregistered / Unconfirmed
GUEST, unregistred user!
用getcursorpos时菜单在鼠标点击处弹出
procedure TForm1.Button1Click(Sender: TObject);
var
p:TPoint;
begin
getcursorpos(p);
PopupMenu1.popup(p.x,p.y);
end;

还有一种方法效果更好:
procedure TForm1.Button1Click(Sender: TObject);
var
p:TPoint;
begin
p:=clienttoscreen(point(Button1.left,Button1.top+Button1.Height));
PopupMenu1.popup(p.X,p.Y);
end;

以上的程序在delphi6.0,win2000下通过
 
P

pink_wt

Unregistered / Unconfirmed
GUEST, unregistred user!
不好意思,我没看清你的题目,我现在又办法了
如果把一个button1放置在一个panel1中,那么
procedure TForm1.Button1Click(Sender: TObject);
var
p:TPoint;
begin
p:=panel1.clienttoscreen(point(Button1.left,Button1.top+Button1.Height));
PopupMenu1.popup(p.X,p.Y);
end;

如果不加入panel1的话,那么clienttoscreen就是相对于form的,
所以现在button可以放在任意多的容器中,只要加入他的parent.clienttoscreen就搞定了

不知现在是否满意?

 
D

delphilai

Unregistered / Unconfirmed
GUEST, unregistred user!
tmd,其实只要用
var
p:TPoint;
begin
p:=TBitBtn(sender).Parent.clienttoscreen(point(TBitBtn(sender).left,TBitBtn(sender).top+TBitBtn(sender).Height));
PopupMenu1.popup(p.X,p.Y);
end;
 
D

delphilai

Unregistered / Unconfirmed
GUEST, unregistred user!
我怎么就没想到利用它的Parent呢
 

Similar threads

S
回复
0
查看
626
SUNSTONE的Delphi笔记
S
S
回复
0
查看
706
SUNSTONE的Delphi笔记
S
D
回复
0
查看
746
DelphiTeacher的专栏
D
D
回复
0
查看
748
DelphiTeacher的专栏
D
顶部 底部