弹出菜单点击源自哪个组件
将弹出菜单附加到表单上的多个组件(按钮,还有 TCharts 等),我想知道首先右键单击哪个组件来启动弹出菜单。
click 方法的 Sender 参数仅指向 TMenuItem,它是弹出菜单(或父菜单项)的父级。
如何获取原始组件?
Having a popup menu attached to several components on a form (buttons, but also things like TCharts), I would like to know which component was right clicked to start the popup menu in the first place.
The Sender parameter of the click method just points to the TMenuItem, its parent to the popup menu (or the parenting menu item).
How do I get the originating component?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您的意思是 PopupMenu1.PopupComponent 吗?
Did you mean PopupMenu1.PopupComponent ?
在 PopupMenu 的 TMenuItem 的单击事件中获取调用者组件:
您可以通过分配给多个列表框并解决导出到文件功能的 PopupMenu 示例,
You can get the caller component within the click event of the TMenuItem of a PopupMenu by
An Example of a PopupMenu which is assigned to several list boxes and solves the export to file functionality:
作为最后的手段,您可以使用
TPopupMenu.OnPopup
中的Mouse.CursorPos
在表单上查找此组件。但可能有更好/更简单的方法。As a last resort you can use
Mouse.CursorPos
inTPopupMenu.OnPopup
to find this component on a form. But there is probably a better/easier way.PopUpMenu.PopupComponent 表示最后响应鼠标右键显示弹出菜单的组件
PopUpMenu.PopupComponent indicates the component that last displayed the popup menu in response to the right mouse click
我有一堆面板,我想让用户右键单击这些面板中的任何一个并执行“删除文件”操作。
因此,我有一个与所有这些面板关联的弹出菜单。
这就是我如何找出哪个面板被右键单击:(
注意:我添加了很多注释来清楚地解释它是如何工作的。但是如果您不喜欢它,您可以将代码压缩为 2 行(请参阅第二个过程) )。
因此,如果您为该弹出菜单分配了操作:
如果您只有一个简单的弹出菜单(未分配操作):
您可以放置所有代码在返回 TPanel 的单个函数中并像这样调用它:
I have a bunch of panels and I want to let the user right click any of those panels and perform a "delete file" action.
So, I have a single pop-up menu associated with all those panels.
This is how I find out which panel was right clicked:
(Note: I put lots of comments to clearly explain how it works. But if you don't like it, you can compactify the code to 2 lines (see the second procedure)).
So, if you have actions assigned to that pop-up menu:
If you only have a simple pop-up menu (no actions assigned):
You can put all that code in a single function that returns a TPanel and call it like this:
对于 Firemonkey 框架,相同函数的工作方式如下,以 PopupMenu 为例,该菜单分配给多个列表框并解决导出到文件功能:
For the Firemonkey framework the same function works as follows for an example of a PopupMenu which is assigned to several list boxes and solves the export to file functionality: