• Have Any Question?
  • contact@eitworld.com

csharp.net checkbox control





    • The CheckBox control is a small rectangle with a corresponding text displayed at the right side of it. This text works as a Label for the checkbox.
    • When you want the user to have multiple options to choose from the existing list you use the CheckBox control.
    • You can place a CheckBox control on the form by drag and drop it from the toolbox. The CheckBox control looks like as follows:

checkbox-control

Properties of CheckBox Control

Some of the commonly used properties of CheckBox Control are listed below in the Table:

checkbox-control

Events of CheckBox Control

Some of the commonly used events of CheckBox Control are listed below in the Table:

checkbox-control

Methods of CheckBox Control

Some of the commonly used Methods of CheckBox Control are listed below in the Table:

checkbox-control

Example

Here is a simple example of CheckBox control. To understand the use of the CheckBox control follows the given steps:

    • Add Two CheckBox controls and a TextBox control on the form from the toolbox.
    • Now double click on CheckBox1 and add the following code in its code-window:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
textBox1.Text = “You clicked at Checkbox1”;
}
}

    • In the above code the Checked property of the checkbox1 returns a Boolean value either True or false indicating whether the checkbox was selected or not. If true a then the text box will display the message ‘You clicked at Checkbox1’.
    • Now double click on CheckBox2 and add the following code in its code-window:
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked == true)
{
textBox1.Text = “You clicked at Checkbox2”;

}
}

    • Now run the application using F5 key. This will generate a Form. Click on CheckBox1 this will display a text in the textbox as follows:
checkbox-control
checkbox-control
    • Now when you click on the CheckBox2 you will see another message in the TextBox. You can also see that after clicking on the second check box, the first check box still remain selected. It is the advantage of the Checkbox control that it allows multiple selections at the same time.

checkbox-control



Real Time Web Analytics