Gtk 中的弹出菜单#
我有一个 Gtk 滚动窗口,我试图附加一个 PopupMenuHandler 函数,如下所示:
this.scrolledwindow1.PopupMenu += HandlePopupMenu;
HandlePopupMenu 看起来像这样:
[GLib.ConnectBefore]
public void HandlePopupMenu(object o, PopupMenuArgs args)
{
Console.WriteLine("test");
Gtk.Menu mbox = new Gtk.Menu();
Gtk.MenuItem Test = new Gtk.MenuItem("test");
Test.Activated += delegate(object sender, EventArgs e) {
Console.WriteLine("test");
};
mbox.Append(Test);
mbox.ShowAll();
mbox.Popup();
}
我的问题是,当我右键单击滚动窗口时,该事件永远不会被调用。 我认为它应该基于 this。 只有一个其他事件处理 ScrollEvent,没有任何事件处理键盘或鼠标按钮。 有人能告诉我为什么这不起作用吗?
I have a Gtk scrolled window that I'm trying to attach a PopupMenuHandler function too like so:
this.scrolledwindow1.PopupMenu += HandlePopupMenu;
and the HandlePopupMenu looks like so:
[GLib.ConnectBefore]
public void HandlePopupMenu(object o, PopupMenuArgs args)
{
Console.WriteLine("test");
Gtk.Menu mbox = new Gtk.Menu();
Gtk.MenuItem Test = new Gtk.MenuItem("test");
Test.Activated += delegate(object sender, EventArgs e) {
Console.WriteLine("test");
};
mbox.Append(Test);
mbox.ShowAll();
mbox.Popup();
}
My problem is that this event never gets called when I right click on the scrolled window. which I'm assuming it should based on this. There is only one other event handling the ScrollEvent, and nothing handling keyboard or mouse buttons. Can anybody tell my why this isn't working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 不要将弹出菜单添加到
GtkScrolledWindow
中,而是添加到它的内容中。 默认情况下,它的大多数事件都是禁用的,通常,用户确实不希望滚动条上有任何弹出窗口。2)
PopupMenu
信号仅针对键盘快捷键(Shift+F10 或菜单按钮)调用,而不是鼠标右键单击。GtkStatusIcon
不是从GtkWidget
派生的,因此它的工作方式不同。您需要实现
ButtonPressEvent
和PopupMenu
信号来让鼠标和键盘显示菜单。 关于实现弹出菜单的 GTK+ 文档 (C ,但不是 C#)。1) Don't add popup menu to
GtkScrolledWindow
but to it's content. Most of it's events is disabled by default and generally, users really don't want any popups on their scroll bars.2)
PopupMenu
signal is only invoked for keyboard shortcuts (Shift+F10 or Menu button), not mouse right clicks.GtkStatusIcon
isn't derived fromGtkWidget
so it works differently.You need to implement
ButtonPressEvent
andPopupMenu
signals to get both mouse and keyboard to show the menu. GTK+ documentation on implementing popup menu (C, not C# though).