CheckBox


A CheckBox displays a box that enables the user to select or clear an option.

A CheckBox can display a textual caption, a picture, or both. Use the ImageAlign and TextAlign properties to determine where the caption and picture appear in the CheckBox.

You can also use the control’s ImageList and ImageIndex properties to assign an image to the CheckBox.

Use the control’s CheckAlign property to determine where the check box appears. Normally the box appears on the left, but you can make it appear on the right, center, upper-left corner, and so forth.

Usually a program uses the CheckBox control’s Checked property to tell if it is checked. This property returns True if the CheckBox is checked and False if it is not. Your program can also set this property to True or False to check or uncheck the control.

Although a CheckBox usually is either checked or not, this control also has a third indeterminate state. This state is represented as a grayed-out check in the box. Some applications use this state to represent a partial or unknown selection.

For example, some installation programs allow the user to select categories of files to install. Selecting the box next to the Images choice would install all of the program’s image files. Clearing this box would tell the program not to install any images. Some programs enable you to click a plus sign or some other indicator to expand the Images category and select the specific files you want to install. In that case, the program displays the check box in the indeterminate state to indicate that you selected some but not all of the files.

If you want to allow the user to cycle through the three values (checked, indeterminate, and unchecked), set the control’s ThreeState property to True.

Most programs use CheckBoxes to gather information and only process the information when the user clicks a button or selects a menu item, so they don’t need to process any CheckBox events. The control does provide a CheckedChanged event, however, that fires whenever the control’s value changes, either because the user clicked it or because your program’s code changed the value. For example, the program could hide and display extra information that only applies when the box is checked, as shown in the following code:

  Private Sub chkExtraInfo_CheckedChanged(ByVal sender As System.Object, _  ByVal e As System.EventArgs) Handles chkExtraInfo.CheckedChanged     grpExtraInfo.Visible = chkExtraInfo.Checked End Sub 




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net