Delphi自定义弹出/下拉菜单,怎么样? [英] Delphi Custom popup/dropdown, how?
问题描述
我想制作一个自定义的dropdow /弹出菜单,下面有一个阴影。问题是它不是一个标准菜单,我需要在弹出/下拉菜单中放置一些组件。所以基本上我想要一个下拉菜单,我可以做任何我想要的,不仅限于简单的menuitems。我想让它像一个普通的弹出菜单的问题是从哪里开始。任何解决方案?参考?
I want to make a custom dropdow/popup menu with a shadow nicely beneath it. The problem is that it is not a standard menu and I need to put some components on the popup/dropdown. So basically I want a dropdown I can do whatever I want with, not being limited to simple menuitems. I want it to act like a normal popupmenu problem is where do I start. Any solutions? References?
推荐答案
听起来你想要一个看起来像一个弹出菜单,但包含组件的表单。
It sounds like you want a form that looks like a popup menu, but contains components.
如果您有一个具有OnMouseDown事件的组件(如该示例中显示的TPanel),并且您只需弹出一个包含要弹出的控件的第二个窗体,则会更容易:
It is easier if you have a component that has an OnMouseDown event, like the TPanel shown in this sample, and you just pop up a second form which contains the controls you wanted to pop up:
procedure TForm3.JvPanel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button=mbRight then
FDown := true
else
FDown := false;
end;
procedure TForm3.JvPanel1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
pt:TPoint;
begin
if Button=mbRight then begin
FDown := true;
pt.X := jvPanel1.Left;
pt.Y := jvPanel1.Top+jvPanel1.Height;
pt := ClientToScreen(pt);
Form4.Position := poDesigned;
Form4.BorderStyle := bsNone;
Form4.Left := pt.X;
Form4.Top := pt.Y;
Form4.Show;
end;
end;
它处理显示自己的表单,并将其定位为一个弹出窗口。
隐藏本身的第二个表单,也很容易:
That handles the form showing itself, and positioning itself to look like a popup. the second form hiding itself, is easy too:
procedure TForm4.FormDeactivate(Sender: TObject);
begin
Hide;
end;
alt text http://img718.imageshack.us/img718/8171/formlookslikepopup.png
这篇关于Delphi自定义弹出/下拉菜单,怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!