[Gtk-sharp-list] RadioButton using Stock Icons

Joachim Jaeckel mono at coffeebreak.de
Wed Aug 17 17:26:51 EDT 2005


Am Dienstag, den 16.08.2005, 17:18 -0400 schrieb Scott Ellington:
> I need to use the RadioButton class for a set of tools in which only one
> can be enabled at one time.  I want to use stock buttons if possible as
> they are common tools such as "Zoom In" and "Zoom Out"  Has anybody done
> this?

Hello Scott, I did it with the ToggleButtons (see the code-example
below) it needs a bit improvement, because currently you can release a
ToggleButton im my example, which should be prevented, but may be you
could get the idea...

Regards,
Joachim.

---------snip-------

namespace xyz {
  public class bla
  {
    bool inToggleFlow = false;
    ToggleButton record;
    ToggleButton edit;
    ToggleButton export;

    ...

    private Widget MakeMainView () {

      ...

      VBox actions = new VBox();
      actions.Spacing = 12;
			
      record = new ToggleButton ();
      record.Add(Utils.CreatePicLabelWidget("camera.png", "Record"));
      record.Clicked += BtnClicked; 
      actions.PackStart(record, false, false, 0);
			
      edit = new ToggleButton();
      edit.Add(Utils.CreatePicLabelWidget("movie.png", "Edit"));
      edit.Clicked += BtnClicked;
      actions.PackStart(edit, false, false, 0);
			
      export = new ToggleButton();
      export.Add(Utils.CreatePicLabelWidget("export.png","Export"));
      export.Clicked += BtnClicked;
      actions.PackStart(export, false, false, 0);

      ...
    }

    private void BtnClicked (object obj, EventArgs args) {
		
      if (! inToggleFlow) {

        if (obj.Equals (record)) {

          inToggleFlow = true;
          edit.Active = false;
          export.Active = false;
          inToggleFlow = false;
          scenes.Unmap ();

        } else if (obj.Equals (edit)) {

          inToggleFlow = true;
          record.Active = false;
          export.Active = false;
          inToggleFlow = false;
          scenes.Map ();

        } else if (obj.Equals (export)) {

          inToggleFlow = true;
          record.Active = false;
          edit.Active = false;
          inToggleFlow = false;
          scenes.Unmap ();

        }

      }

    }
		
  }

}

---- new file ----

using System;
using Gdk;
using Gtk;
using Gnome;

namespace VEdit.UI.GtkUi {

  public class Utils {
	
    public static HBox CreatePicLabelWidget(String pic, String lab) {
      HBox hb = new HBox();

      hb.PackStart(new Gtk.Image(new Gdk.Pixbuf(null, pic)), false,
false, 0);
      hb.PackStart(new Label(lab), true, true, 5);
			
      return hb;
    }
  }
}




More information about the Gtk-sharp-list mailing list