CheckBox Control in VB.Net

CheckBoxes are user interface elements that facilitate multiple selections from a range of options. Users can interact with a CheckBox by clicking on it to select or deselect it. When a CheckBox is selected, it displays a checkmark, indicating that the option has been chosen. Clicking on the CheckBox again removes the checkmark, deselecting the option.

vb.net-checkbox.jpg

CheckBox Caption Property

CheckBoxes are equipped with a caption, which is the text displayed alongside the CheckBox itself. The caption provides a descriptive label or prompt that helps users understand the purpose or meaning of the CheckBox. The Text property of a CheckBox allows you to set or modify this caption according to your specific requirements.

CheckBox1.Text = "Net-informations.com"

By customizing the Text property, you can provide clear and meaningful labels for the CheckBoxes, ensuring that users can easily comprehend the purpose of each option. This enhances the usability of your application and facilitates effective communication between the user and the program.

ThreeState property

The CheckBox control in VB.Net provides a ThreeState property that allows you to enable and utilize three different states: Checked, Unchecked, and Indeterminate. By setting the ThreeState property to True, you indicate that you want the CheckBox control to support these three distinct states.

When the ThreeState property is enabled, the CheckBox can be in one of the following three states:

  1. Checked: This state indicates that the option associated with the CheckBox is selected.
  2. Unchecked: This state represents that the option associated with the CheckBox is not selected.
  3. Indeterminate: This state signifies a neutral or unknown state, where neither checked nor unchecked is explicitly indicated. The Indeterminate state is typically represented by a visual indication such as a horizontal line inside the CheckBox.

Enabling the ThreeState property allows you to use the CheckBox control's versatility in scenarios where you need to represent and handle multiple states or where a neutral state is meaningful. This can be particularly useful when dealing with complex options or situations where the user needs to indicate uncertainty or a partial selection.

CheckBox1.ThreeState = True

To apply the same property settings to multiple CheckBox controls, use the Style property. The following VB.Net program shows how to find a checkbox is selected or not.

Full Source VB.NET
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim msg As String = "" If CheckBox1.Checked = True Then msg = "net-informations.com" End If If CheckBox2.Checked = True Then msg = msg & " https://net-informations.com/vb/default.htm" End If If CheckBox3.Checked = True Then msg = msg & " csharp.net-informations.com" End If If msg.Length > 0 Then MsgBox(msg & " selected ") Else MsgBox("No checkbox selected") End If CheckBox1.ThreeState = True End Sub End Class

Conclusion

With the ability to select or deselect multiple options and the inclusion of informative captions, CheckBoxes serve as valuable user interface elements for handling scenarios that require the selection of multiple choices from a list of options.