[Gtk-sharp-list] Using RadioButtons

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


Jeremiah McElroy wrote:
> I have an app with a Gtk.Dialog that contains a group of RadioButtons.  
> I would like to use the radio buttons to set a user preference in the 
> application.  I can't seem to find any examples (in either MS or Mono 
> docs) about how to do this.  If anyone has an example or advice, I would 
> greatly appreciate it.

This example works for me. I don't know if this is very correct, but it 
works:

using System;
using Gtk;
using GtkSharp;
class Capp {
	Gtk.Window win;
	RadioButton rb1,rb2,rb3;
	Table t;
	Capp() {
		win = new Gtk.Window("Trest");
		win.DeleteEvent += new DeleteEventHandler(Quit);
		t = new Table(3,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;
		t.Attach(rb1,0,1,0,1);
		t.Attach(rb2,0,1,1,2);
		t.Attach(rb3,0,1,2,3);
		win.Add(t);
		win.ShowAll();
	}
	static void Main() {
		Application.Init();
		Capp win = new Capp();
		Application.Run();
	}
	void Quit(object o, DeleteEventArgs a) {
		Application.Quit();
	}
}