views:

262

answers:

1
+1  Q: 

PopupMenu in Gtk#.

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  A: 

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).

Ivan Baldin
Thanks for the info. I'd already started implementing the ButtonPressEvent but was curious about the PopUpMenu event.
AvatarOfChronos