vbnet
  1. vbnet-checkbox-control

Working with Forms and Controls in VB.NET CheckBox Control

The CheckBox control in VB.NET is used to display a checkable option in the user interface. It is commonly used to get a yes or no answer from the user.

Syntax

The syntax to declare a CheckBox control in VB.NET is:

Dim chkBox As New CheckBox()

Example

Here is an example that demonstrates the use of the CheckBox control in VB.NET:

Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
    If CheckBox1.Checked = True Then
        MessageBox.Show("CheckBox is checked")
    Else
        MessageBox.Show("CheckBox is unchecked")
    End If
End Sub

Output

When you run the above example and check or uncheck the CheckBox control, the MessageBox will display "CheckBox is checked" or "CheckBox is unchecked", respectively.

Explanation

In the above example, we have created a CheckBox control and added an event handler for the CheckedChanged event. The event handler checks the value of the Checked property of the CheckBox control and displays the appropriate message in a MessageBox dialog.

Use

The CheckBox control is commonly used in VB.NET to get a yes or no answer from the user. It can be used to ask for user preferences, such as whether to enable or disable a feature, or to select options from a list.

Important Points

  • The Checked property of the CheckBox control is used to get or set the checked state of the control.
  • The CheckedChanged event is raised when the checked state of the CheckBox control changes.

Summary

In summary, the CheckBox control in VB.NET is used to display a checkable option in the user interface. It is commonly used to get a yes or no answer from the user and can be used to ask for user preferences or to select options from a list. The Checked property is used to get or set the checked state of the control, while the CheckedChanged event is raised when the checked state changes.

Published on: