CheckBox.CheckState Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the state of the CheckBox.
public:
property System::Windows::Forms::CheckState CheckState { System::Windows::Forms::CheckState get(); void set(System::Windows::Forms::CheckState value); };
[System.ComponentModel.Bindable(true)]
public System.Windows.Forms.CheckState CheckState { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.CheckState : System.Windows.Forms.CheckState with get, set
Public Property CheckState As CheckState
Property Value
One of the CheckState enumeration values. The default value is Unchecked
.
- Attributes
Exceptions
The value assigned is not one of the CheckState enumeration values.
Examples
The following code example displays the values of three properties in a label. The ThreeState property alternates between true
and false
with alternating clicks of the control and the CheckAlign alternates between the MiddleRight
and MiddleLeft
values of System.Drawing.ContentAlignment. This example shows how the property values change as the ThreeState property changes and the control is checked. This example requires that a CheckBox, Label and Button have all been instantiated on a form and that the label is large enough to display three lines of text, as well as a reference to the System.Drawing namespace. This code should be called in the Click event handler of the control.
private:
void AdjustMyCheckBoxProperties()
{
// Concatenate the property values together on three lines.
label1->Text = String::Format( "ThreeState: {0}\nChecked: {1}\nCheckState: {2}",
checkBox1->ThreeState, checkBox1->Checked, checkBox1->CheckState );
// Change the ThreeState and CheckAlign properties on every other click.
if ( !checkBox1->ThreeState )
{
checkBox1->ThreeState = true;
checkBox1->CheckAlign = ContentAlignment::MiddleRight;
}
else
{
checkBox1->ThreeState = false;
checkBox1->CheckAlign = ContentAlignment::MiddleLeft;
}
}
private void AdjustMyCheckBoxProperties()
{
// Change the ThreeState and CheckAlign properties on every other click.
if (!checkBox1.ThreeState)
{
checkBox1.ThreeState = true;
checkBox1.CheckAlign = ContentAlignment.MiddleRight;
}
else
{
checkBox1.ThreeState = false;
checkBox1.CheckAlign = ContentAlignment.MiddleLeft;
}
// Concatenate the property values together on three lines.
label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" +
"Checked: " + checkBox1.Checked.ToString() + "\n" +
"CheckState: " + checkBox1.CheckState.ToString();
}
Private Sub AdjustMyCheckBoxProperties()
' Change the ThreeState and CheckAlign properties on every other click.
If Not checkBox1.ThreeState Then
checkBox1.ThreeState = True
checkBox1.CheckAlign = ContentAlignment.MiddleRight
Else
checkBox1.ThreeState = False
checkBox1.CheckAlign = ContentAlignment.MiddleLeft
End If
' Concatenate the property values together on three lines.
label1.Text = "ThreeState: " & checkBox1.ThreeState.ToString() & ControlChars.Cr & _
"Checked: " & checkBox1.Checked.ToString() & ControlChars.Cr & _
"CheckState: " & checkBox1.CheckState.ToString()
End Sub
Remarks
If the ThreeState property is set to false
, the CheckState property value can only be set to CheckState.Indeterminate
in code and not by user interaction.
The following table describes the System.Windows.Forms.Appearance of the CheckBox control in its different states for the Normal
and Button
style control CheckBox.Appearance.
CheckState | Appearance.Normal | Appearance.Button |
---|---|---|
Checked |
The CheckBox displays a check mark. | The control appears sunken. |
Unchecked |
The CheckBox is empty. | The control appears raised. |
Indeterminate |
The CheckBox displays a check mark and is shaded. | The control appears flat. |