[Mono-list] GTK# Stock Icon

Milen Dzhumerov gamehack@1nsp1r3d.co.uk
Tue, 26 Apr 2005 22:14:24 +0100

Ben Motmans wrote:

>On 4/22/05, Milen Dzhumerov <gamehack@1nsp1r3d.co.uk> wrote:
>>Hi all,
>>I've been reading Mono: A Developer's Notebook and I couldn't find a way
>>of creating an icon with a stock image. I looked at
>>www.go-mono.com/docs/ for Icon related classes but couldn't figure out
>>how to do it. My other question is, is it possible to show a menu if the
>>user clicked on the icon?
>You don't need to use the Icon class, but the Image class
>Image img = new Image("gtk-save", IconSize.Menu);
>It is also possible to show a menu if a user clicks on the image, but
>you need to add the Image to an EventBox, since an Image cannot fire
>EventBox eb = new EventBox();
>EventBox.Add(new Image("gtk-save", IconSize.Menu);
>EventBox.ButtonPressEvent += new ButtonPressEventHandler (OnImageClick);
>private void OnImageClick (object o, ButtonPressEventArgs args)
>   if (args.Event.Button == 3) { //right click
>      Menu popupMenu = new Menu();
>      MenuItem menuPopup1 = new MenuItem ("Popup item 1");
>      popupMenu.Add (menuPopup1);
>      popupMenu.Popup (null, null, null, IntPtr.Zero,
>args.Event.Button, args.Event.Time);
>      popupMenu.ShowAll ();
>   }
>But are you sure you really want a stock image with a menu popping up
>if the user clicks the image? there are nice ways of doing someting
>similar, like a Toolbar with a Gtk.MenuToolButton (some sort of combo
>box) or ...
>-- Ben
>Mono-list maillist  -  Mono-list@lists.ximian.com

I want to use this for a tray icon. Here's the sample code - 
http://www.1nsp1r3d.co.uk/tmp/mono/TrayIcon.cs. I want to replace this line:

icon.Add (new Label ("Testing"));

with your code, but I'm not sure whether it will work out. And as a side 
not, I couldn't find the method documented anywhere.