CheckBox Control for VB.net

Source: Internet
Author: User

A checkbox (CheckBox) control is used to identify whether an option is a selected state. Therefore, you typically use this control to provide "yes/no" or "True/false" options. The checkbox controls that can be grouped display multiple sets of different types of options from which a user can select one or more options. The icon for the CheckBox control in the Toolbox is as shown in the figure:

Both the CheckBox control and the Radiobox (radio box) control can be used to indicate whether the user chooses an option. The difference is that for a group of Radiobox controls, you can select only one of them at a time, and you can select any number of check boxes for all the checkbox controls. The Radiobox control is described further later.
1.CheckState Properties
The CheckState property of the CheckBox control indicates which of the check boxes are in the selected, unselected, or prohibited State (dim). When selected, the CheckState setting value is 1.
The following table provides the values for setting the CheckState property and the corresponding Visual Basic constants:

value constant
0 checkstate.unchecked
1 indeterminate

The user clicks the CheckBox control to specify the selected or unselected state, and then detects control state and writes the application based on this information to perform certain actions. By default, the CheckBox control is set to checkstate.unchecked. To select several check boxes in advance in a column of check boxes, You should set the CheckState property to checkstate.checked in the new or InitializeComponent procedure to select the check box, and you can set the CheckState property to CheckState.Indeterminate to disable the check box. For example, you may sometimes want to disable a check box before a condition is met.
2.Click Event
Whenever you click the CheckBox control, it triggers the Click event and then writes the application to perform certain actions based on the state of the check box. In the following example, each time a CheckBox control is clicked, its Text property is changed to indicate the selected or unselected state:

Protected Sub Checkbox1_click (ByVal sender as Object,byval as_ System.EventArgs
                       ) Handles Checkbox.click
    If checkbox1.checkstate=checkstate.checked Then
       checkbox1.text= "Checked"
    ElseIf checkbox1.checkstate= checkstate.unchecked Then
       checkbox1.text= "UnChecked" End
    If

Note: If you try to double-click the CheckBox control, double-click it as a two-click and handle two clicks, which means that the CheckBox control does not support double-clicking events.
3. Responding to mouse and keyboard
The CheckBox control's Click event is also triggered by using the TAB key on the keyboard and pressing the SPACEBAR key, which shifts the focus to the CheckBox control. You can add hyphens before one letter of the Text property and create a keyboard shortcut to toggle the selection of the CheckBox control.
4. Enhance the visual effects of the CheckBox control
The checkbox control, like a button and a RadioButton control, can enhance its visual effects by changing the setting value of the Style property and using the image, ImageAlign, ImageIndex, and ImageList properties. For example, you might sometimes want to add an icon or bitmap to a check box, or display a different image when you click or disable a control.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.