简体   繁体   English

模仿Gtk#/ gtk-sharp中的上下文菜单

[英]Imitating a context menu in Gtk#/gtk-sharp

Is there some way to use the Menu.AttachToWidget(...) function of a gtk menu item to attach the menu to say a Gtk.Textview and have it handle showing the menu when needed. 有什么方法可以使用gtk菜单项的Menu.AttachToWidget(...)函数将菜单附加为Gtk.Textview并使其在需要时处理以显示菜单。 Or is creating an event handler for ButtonPressEvent and showing the menu there the only way to do it? 还是为ButtonPressEvent创建事件处理程序并在那里显示菜单是唯一的方法?

Or is there a third possibility that I'm missing? 还是我想念的第三种可能性?

Thanks in Advance. 提前致谢。

There is a third possibility that you are missing. 您有第三种可能性失踪。

TextView.PopulatePopup is an event that TextView fires when the user right clicks within the TextView. TextView.PopulatePopup是一个事件,当用户右键单击TextView时,TextView将触发。 You can handle this event and insert menu items into the existing TextView context menu, which has items for cut/copy/paste and input method. 您可以处理此事件,并将菜单项插入到现有的TextView上下文菜单中,该菜单包含用于剪切/复制/粘贴和输入法的项。 This is the preferred way of adding additional context menu items to TextView. 这是向TextView添加其他上下文菜单项的首选方法。

Links to docs: 链接到文档:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM