如何为 Delphi 组件创建上下文菜单?
我想为 Delphi 组件创建一个上下文菜单,例如 TDBGrid、TTreeView 或类似组件。我怎样才能做到这一点?
I want to create a context menu for Delphi components like TDBGrid
, TTreeView
or similar. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 TPopupMenu 放置到您的表单上并用它设计您的菜单。然后选择弹出菜单适用的组件(DbGrid、TreeView...)并将其 PopupMenu 属性设置为您刚刚设计的 PopupMenu。
不同的组件可以有不同的弹出菜单。
Place a TPopupMenu onto your form and design your menu with it. Then select the component the popupmenu is meant for (DbGrid, TreeView, ...) and set it's PopupMenu property to the PopupMenu you just designed.
You can have different PopupMenus for different components.
放置 TPopupmenu 控件并将其链接到所需控件后,如果您想根据树视图中选定的单元格或节点更改弹出菜单中的可用项目,请使用该控件的 OnContextPopup 事件,这使您有机会更改弹出菜单的默认行为
After placing a TPopupmenu control and linking it to the desired control, if you want to change the available items in the popup menu according to the selected cell or node in a treeview use the OnContextPopup event of the control, that gives you a chance to alter the default behaivor of the Popupmenu