- Back to Home »
- Windows Applications »
- CheckBox
Posted by :
Sudhir Chekuri
Monday, 15 February 2016
It allows you to check multiple or even all of the checkboxes.
Default event: CheckedChanged
Checked changed event is fired every time when a user select or deselect the checkbox.
Checked: Determines if the checkbox is checked.
CheckState: Tells whether the checkbox is Checked, Unchecked.
ThreeState: If true, the checkbox can accept an Intermediate state.
Example to show selected items using checkboxes on button click
Default event: CheckedChanged
Checked changed event is fired every time when a user select or deselect the checkbox.
private void
checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
checkBox1.Text = "Selected";
}
else
{
checkBox1.Text = "Not
Selected";
}
}
Checked: Determines if the checkbox is checked.
CheckState: Tells whether the checkbox is Checked, Unchecked.
ThreeState: If true, the checkbox can accept an Intermediate state.
Example to show selected items using checkboxes on button click
private void button1_Click(object sender, EventArgs e)
{
string items = String.Empty;
if (checkBoxSoap.Checked)
items += "\n
Soap";
if (checkBoxShampoo.Checked)
items += "\n
Shampoo";
if (checkBoxToothpaste.Checked)
items += "\n
Toothpaste.";
MessageBox.Show("You have bought: " + items);
}