Thursday, August 27, 2009

Windows Programming - Working with CheckBox

using System;
using System.Windows.Forms;
using System.Drawing;
class myfrm : Form
{
CheckBox c;
Button b;
public myfrm()
{
c=new CheckBox();
c.Text="Subject";
c.SetBounds(100,100,150,50);
this.Controls.Add(c);

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 (c.CheckState == CheckState.Checked)
{
MessageBox.Show("subject selected");
}
if (c.CheckState == CheckState.Unchecked)
{
MessageBox.Show("subject not selected");
}
}
}
class Program
{
static void Main(string[] args)
{
myfrm f = new myfrm();
f.ShowDialog();
}
}

No comments:

Post a Comment