Export (0) Print
Expand All

CheckBox Class

Represents a Windows check box.

For a list of all members of this type, see CheckBox Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            System.Windows.Forms.ButtonBase
               System.Windows.Forms.CheckBox

[Visual Basic]
Public Class CheckBox
   Inherits ButtonBase
[C#]
public class CheckBox : ButtonBase
[C++]
public __gc class CheckBox : public ButtonBase
[JScript]
public class CheckBox extends ButtonBase

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

Use a CheckBox to give the user an option, such as true/false or yes/no. The check box control can display an image or text or both.

CheckBox and RadioButton controls have a similar function: they allow the user to choose from a list of options. CheckBox controls let the user pick a combination of options. In contrast, RadioButton controls allow a user to choose from mutually exclusive options.

The Appearance property determines whether the check box appears as a typical check box or as a button.

The ThreeState property determines whether the control supports two or three states. Use the Checked property to get or set the value of a two-state check box control and use the CheckState property to get or set the value of a three-state check box control.

Note   If the ThreeState property is set to true, the Checked property will return true for either a checked or indeterminate state.

The FlatStyle property determines the style and appearance of the control. If the FlatStyle property is set to FlatStyle.System, the user's operating system determines the appearance of the control.

Note   When the FlatStyle property is set to FlatStyle.System, the CheckAlign property is ignored and the control is displayed using the ContentAlignment.MiddleLeft or ContentAlignment.MiddleRight alignment. If the CheckAlign property is set to one of the right alignments, the control is displayed using the ContentAlignment.MiddleRight alignment; otherwise, it is displayed using the ContentAlignment.MiddleLeft alignment.

The following describes an indeterminate state: You have a check box that determines if the selected text in a RichTextBox is bold. When you select text you can click the check box to bold the selection. Likewise, when you select some text, the check box displays whether the selected text is bold. If your selected text contains text that is bold and normal, the check box will have an indeterminate state.

Example

The following example creates and initializes a CheckBox, gives it the appearance of a toggle button, sets AutoCheck to false, and adds it to a Form.

[Visual Basic] 
Public Sub InstantiateMyCheckBox()
    ' Create and initialize a CheckBox.   
    Dim checkBox1 As New CheckBox()
    
    ' Make the check box control appear as a toggle button.
    checkBox1.Appearance = Appearance.Button
    
    ' Turn off the update of the display on the click of the control.
    checkBox1.AutoCheck = False
    
    ' Add the check box control to the form.
    Controls.Add(checkBox1)
End Sub 'InstantiateMyCheckBox

[C#] 
public void InstantiateMyCheckBox()
 {
    // Create and initialize a CheckBox.   
    CheckBox checkBox1 = new CheckBox(); 
    
    // Make the check box control appear as a toggle button.
    checkBox1.Appearance = Appearance.Button;
 
    // Turn off the update of the display on the click of the control.
    checkBox1.AutoCheck = false;
 
    // Add the check box control to the form.
    Controls.Add(checkBox1);
 }
 

[C++] 
public:
    void InstantiateMyCheckBox() {
        // Create and initialize a CheckBox.   
        CheckBox __gc *checkBox1 = new CheckBox(); 
    
        // Make the check box control appear as a toggle button.
        checkBox1->Appearance = Appearance::Button;
 
        // Turn off the update of the display on the click of the control.
        checkBox1->AutoCheck = false;
 
        // Add the check box control to the form.
        this->Controls->Add(checkBox1);
    };
 

[JScript] 
public function InstantiateMyCheckBox()
 {
    // Create and initialize a CheckBox.   
    var checkBox1 : CheckBox = new CheckBox(); 
    
    // Make the check box control appear as a toggle button.
    checkBox1.Appearance = Appearance.Button;
 
    // Turn off the update of the display on the click of the control.
    checkBox1.AutoCheck = false;
 
    // Add the check box control to the form.
    Controls.Add(checkBox1);
 }
 

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

CheckBox Members | System.Windows.Forms Namespace | ButtonBase

Show:
© 2014 Microsoft