[Gtk-sharp-list] Using RadioButtons

Antonio Martínez Álvarez amartinez@atc.ugr.es
Mon, 08 Mar 2004 18:20:18 +0100


Jeremiah McElroy wrote:

> Please excuse my ignorance, I just saw ToggleButton.Mode in the 
> documentation, and I assume this is what I need.
> 

Uhm, I have used Active Property from inherited from  ToggledButton.
This works for me:

// Capturing the "checked" property:
using System;
using Gtk;
using GtkSharp;
class Capp {
	Gtk.Window win;
	RadioButton rb1,rb2,rb3;
	Button b;
	Table t;
	Capp() {
		win = new Gtk.Window("Trest");
		win.DeleteEvent += new DeleteEventHandler(Quit);
		t = new Table(4,1, true);
		rb1 = new RadioButton(null, "RB 1");
		rb2 = new RadioButton(null, "RB 2");		
		rb3 = new RadioButton(null, "RB 3");
		rb2.Group = rb1.Group;
		rb3.Group = rb1.Group;
		b = new Button("Which is selected?");
		b.Clicked += new EventHandler(Which);
		t.Attach(rb1,0,1,0,1);
		t.Attach(rb2,0,1,1,2);
		t.Attach(rb3,0,1,2,3);
		t.Attach(b,0,1,3,4);
		win.Add(t);
		win.ShowAll();
	}
	
	static void Main() {
		Application.Init();
		Capp win = new Capp();
		Application.Run();
	}
	void Quit(object o, DeleteEventArgs a) {
		Application.Quit();
	}
	void Which(object o, EventArgs a) {
		if (rb1.Active) {
			Console.WriteLine("RB 1 is actived");
		}
		else if (rb2.Active) {
			Console.WriteLine("RB 2 is actived");
		}
		else if (rb3.Active) {
			Console.WriteLine("RB 3 is actived");
		}


	}
}