Thursday, August 27, 2009

Windows Programming - Working with RadioButton

using System;
using System.Windows.Forms;
using System.Drawing;
class myfrm : Form
{
RadioButton b1, b2;
Button b;
public myfrm()
{

b1 = new RadioButton();
b1.Text = "Male";
b1.SetBounds(100, 100, 150, 50);
this.Controls.Add(b1);
b2 = new RadioButton();
b2.Text = "Female";
b2.SetBounds(100, 200, 150, 50);
this.Controls.Add(b2);
b = new Button();
b.Text = "Ok";
b.SetBounds(100, 300, 150, 50);
this.Controls.Add(b);
b.Click +=new EventHandler(fun);
}
void fun(object o, EventArgs e)
{
if (b1.Checked == true)
{
MessageBox.Show("Male Selected");
}
if (b2.Checked == true)
{
MessageBox.Show("Female Selected");
}
}
}
class Program
{
static void Main(string[] args)
{
myfrm f = new myfrm();
f.ShowDialog();
}
}

No comments:

Post a Comment