Mono: Get value of the selected RadioButton [C#,gtk#]
FROM MONO DOCUMENTATION: @http://www.go-mono.com/docs/index.aspx?link=T%3AGtk.RadioButton
A single radio button performs the same basic function as a k.CheckButton, as its position in the object hierarchy reflects. It is only when multiple radio buttons are grouped together that they become a different user interface component in their own right.
Every radio button is a member of some group of radio buttons. When one is selected, all other radio buttons in the same group are deselected. A Gtk.RadioButton is one way of giving the user a choice from many options.
Radio button widgets are created with RadioButton(string), if this is the first radio button in a group. In subsequent calls, the group you wish to add this button to should be passed as an argument.
I found out that there exists not much examples about this issue so I post mine…
Code:
using Gtk;
using System;
using System.Drawing;
namespace GtkSharpTutorial {
class FRM: Window
{
static GLib.SList group = null;
private RadioButton radiobutton;
private RadioButton radiobutton2;
public FRM()
: base("deneme")
{
Application.Init();
Window window = new Window("radio buttons");
window.BorderWidth = 0;
VBox box1 = new VBox (false, 0);
window.Add(box1);
box1.Show();
VBox box2 = new VBox (false, 10);
box2.BorderWidth = 10;
box1.PackStart(box2, true, true, 0);
box2.Show();
radiobutton = new RadioButton (null, "1");
group = radiobutton.Group;
radiobutton.Active = true;
box2.PackStart(radiobutton, true, true, 0);
radiobutton.Show();
radiobutton2 = new RadioButton (radiobutton, "2");
box2.PackStart(radiobutton2, true, true, 0);
radiobutton2.Show();
radiobutton.Clicked+= new EventHandler(radiobutton_Clicked);
radiobutton2.Clicked+= new EventHandler(radiobutton2_Clicked);
window.ShowAll();
}
public static void Main()
{
Application.Init();
new FRM();
Application.Run();
}
void radiobutton2_Clicked(object sender, EventArgs e)
{
if(radiobutton2.Active==true){
Console.WriteLine("2");
}
}
void radiobutton_Clicked(object sender, EventArgs e)
{
if(radiobutton.Active==true){
Console.WriteLine("1");
}
}
}
}
<pre>
Output:



