[Mono-list] GTK# Stock Icon

Ben Motmans Ben Motmans <ben.motmans@gmail.com>
Fri, 22 Apr 2005 18:15:51 +0200


On 4/22/05, Milen Dzhumerov <gamehack@1nsp1r3d.co.uk> wrote:
> Hi all,
>=20
> 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?
>=20
> Regards,
> gamehack

You don't need to use the Icon class, but the Image class
Image img =3D 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
events

EventBox eb =3D new EventBox();
EventBox.Add(new Image("gtk-save", IconSize.Menu);
EventBox.ButtonPressEvent +=3D new ButtonPressEventHandler (OnImageClick);

private void OnImageClick (object o, ButtonPressEventArgs args)
{
   if (args.Event.Button =3D=3D 3) { //right click
      Menu popupMenu =3D new Menu();
      MenuItem menuPopup1 =3D 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