Export (0) Print
Expand All
5 out of 8 rated this helpful - Rate this topic

CheckBox Class

Represents a Windows CheckBox.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[DefaultBindingPropertyAttribute("CheckState")]
public class CheckBox : ButtonBase

Use a CheckBox to give the user an option, such as true/false or yes/no. The CheckBox 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 CheckBox appears as a typical CheckBox 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 CheckBox control and use the CheckState property to get or set the value of a three-state CheckBox control.

NoteNote:

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.

NoteNote:

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 CheckBox that determines if the selected text in a RichTextBox is bold. When you select text you can click the CheckBox to bold the selection. Likewise, when you select some text, the CheckBox displays whether the selected text is bold. If your selected text contains text that is bold and normal, the CheckBox will have an indeterminate state.

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

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);
 }
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.