Delphi自定义弹出/下拉菜单,如何实现?

发布于 2024-09-04 19:42:57 字数 147 浏览 3 评论 0原文

我想制作一个自定义下拉/弹出菜单,其下方有一个很好的阴影。问题是它不是标准菜单,我需要在弹出菜单/下拉菜单中放置一些组件。所以基本上我想要一个下拉菜单,我可以做任何我想做的事情,而不仅仅是简单的菜单项。我希望它像正常的弹出菜单一样工作,问题是我从哪里开始。有什么解决办法吗?参考?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寒江雪… 2024-09-11 19:42:57

听起来您想要一个看起来像弹出菜单但包含组件的表单。

如果您有一个具有 OnMouseDown 事件的组件(如本示例中所示的 TPanel),并且您只需弹出第二个窗体,其中包含您想要弹出的控件,那就更容易了:

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;

它处理显示自身和定位自身的窗体看起来像一个弹出窗口。
第二种形式隐藏自己,也很容易:

procedure TForm4.FormDeactivate(Sender: TObject);
begin
 Hide;
end;

It sounds like you want a form that looks like a popup menu, but contains components.

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;
音盲 2024-09-11 19:42:57

您可以使用 TPopupMenu 并提供自定义绘图。
这是通过设置

PopupMenu1.OwnerDraw := True;

然后编写 OnMeasureItem()OnAdvancedDrawItem() 事件来确定自定义绘画所需的尺寸来完成的。
然后编写 OnDrawItem() 事件以根据需要绘制画布。

You can use TPopupMenu and provide custom drawing.
This is done by setting

PopupMenu1.OwnerDraw := True;

Then code the OnMeasureItem() or OnAdvancedDrawItem() Event to determine the size you need for the custom painting.
Then code the OnDrawItem() Event to paint the canvas as desired.

掩饰不了的爱 2024-09-11 19:42:57

无论如何,弹出窗口的投影方面现已得到解决在此问题

For what it is worth, the drop shadow aspect of the popup has now been tackled and solved in this question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文