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?
1) Don’t add popup menu to
GtkScrolledWindowbut 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)
PopupMenusignal is only invoked for keyboard shortcuts (Shift+F10 or Menu button), not mouse right clicks.GtkStatusIconisn’t derived fromGtkWidgetso it works differently.You need to implement
ButtonPressEventandPopupMenusignals to get both mouse and keyboard to show the menu. GTK+ documentation on implementing popup menu (C, not C# though).