8.9 Determining Check Box State

 <  Day Day Up  >  

You want to determine whether a check box is checked and also be notified when the state of a check box changes.


Technique

The Checked property of a CheckBox control lets you know whether a check box is checked. To perform an action when the check box is clicked, you can handle the CheckedChanged event. A check box can also have three states if the ThreeState property is set to true . In addition to the checked and unchecked states, a three state check box also has an indeterminate state. For these check boxes, you can view the state using the CheckState property. This property contains a value in the CheckState enumerated data type. Additionally, when a three-state check box's state changes to the CheckState.Indeterminate state, which visually appears as a gray check box that is checked, the CheckedChanged event is not thrown. However, you can create an event handler for the CheckStateChanged event.

Comments

Check box controls are inclusive controls used to control the value of a Boolean variable. In most cases, the check box is either checked ( true ) or unchecked ( false ). However, a check box can also have an indeterminate state, which is shown as a grayed-out check in the check box, as shown in Figure 8.3. In this figure, the application allows you to change the appearance of a label by checking a series of check boxes. The last check box in the group labeled Color is a three-state check box. When the check box is in the CheckState.Indeterminate state, the user wants to change the color of the label but has not checked the Red check box. If this were a real application, then the color choice would obviously have more selections. Once the user checks the Red check box, the state of the Color check box can change to Checked .

Figure 8.3. Check boxes can be in a checked, unchecked, or indeterminate state.

graphics/08fig03.gif

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

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