Delphi自定义弹出/下拉菜单,如何实现?
我想制作一个自定义下拉/弹出菜单,其下方有一个很好的阴影。问题是它不是标准菜单,我需要在弹出菜单/下拉菜单中放置一些组件。所以基本上我想要一个下拉菜单,我可以做任何我想做的事情,而不仅仅是简单的菜单项。我希望它像正常的弹出菜单一样工作,问题是我从哪里开始。有什么解决办法吗?参考?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您想要一个看起来像弹出菜单但包含组件的表单。
如果您有一个具有 OnMouseDown 事件的组件(如本示例中所示的 TPanel),并且您只需弹出第二个窗体,其中包含您想要弹出的控件,那就更容易了:
它处理显示自身和定位自身的窗体看起来像一个弹出窗口。
第二种形式隐藏自己,也很容易:
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:
That handles the form showing itself, and positioning itself to look like a popup.
the second form hiding itself, is easy too:
您可以使用 TPopupMenu 并提供自定义绘图。
这是通过设置
然后编写
OnMeasureItem()
或OnAdvancedDrawItem()
事件来确定自定义绘画所需的尺寸来完成的。然后编写
OnDrawItem()
事件以根据需要绘制画布。You can use TPopupMenu and provide custom drawing.
This is done by setting
Then code the
OnMeasureItem()
orOnAdvancedDrawItem()
Event to determine the size you need for the custom painting.Then code the
OnDrawItem()
Event to paint the canvas as desired.无论如何,弹出窗口的投影方面现已得到解决在此问题。
For what it is worth, the drop shadow aspect of the popup has now been tackled and solved in this question.