Gtk 中的弹出菜单#

发布于 2024-07-27 05:15:50 字数 753 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明媚如初 2024-08-03 05:15:50

1) 不要将弹出菜单添加到 GtkScrolledWindow 中,而是添加到它的内容中。 默认情况下,它的大多数事件都是禁用的,通常,用户确实不希望滚动条上有任何弹出窗口。

2) PopupMenu 信号仅针对键盘快捷键(Shift+F10 或菜单按钮)调用,而不是鼠标右键单击。 GtkStatusIcon 不是从 GtkWidget 派生的,因此它的工作方式不同。

您需要实现 ButtonPressEventPopupMenu 信号来让鼠标和键盘显示菜单。 关于实现弹出菜单的 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 from GtkWidget so it works differently.

You need to implement ButtonPressEvent and PopupMenu signals to get both mouse and keyboard to show the menu. GTK+ documentation on implementing popup menu (C, not C# though).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文