Export (0) Print
Expand All

CheckBox.Checked Property

Gets or set a value indicating whether the check box is in the checked state.

[Visual Basic]
Public Property Checked As Boolean
[C#]
public bool Checked {get; set;}
[C++]
public: __property bool get_Checked();
public: __property void set_Checked(bool);
[JScript]
public function get Checked() : Boolean;
public function set Checked(Boolean);

Property Value

true if the check box is in the checked state; otherwise, false. The default value is false.

Note   If the ThreeState property is set to true, the Checked property will return true for either a Checked or Indeterminate CheckState.

Remarks

When the value is true, the check box portion of the control displays a check mark. If the Appearance property is set to Button, the control will appear sunken when Checked is true and raised like a standard button when false.

Example

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 button and the CheckAlign alternates between MiddleRight and MiddleLeft. This example shows how the property values change as the ThreeState property changes and the button is checked. This code assumes 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 button.

[Visual Basic] 
Private Sub AdjustMyCheckBoxProperties()
    ' 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()
    
    ' 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
End Sub 'AdjustMyCheckBoxProperties

[C#] 
private void AdjustMyCheckBoxProperties()
 {
    // Concatenate the property values together on three lines.
    label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" +
                  "Checked: " + checkBox1.Checked.ToString() + "\n" +
                  "CheckState: " + checkBox1.CheckState.ToString(); 
    
    // 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;
    }
 }
 

[C++] 
private:
void AdjustMyCheckBoxProperties()
 {
    // Concatenate the property values together on three lines.
    label1->Text = String::Format( S"ThreeState: {0}\nChecked: {1}\nCheckState: {2}",
        __box(checkBox1->ThreeState), __box(checkBox1->Checked), __box(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;
    }
 }
 

[JScript] 
private function AdjustMyCheckBoxProperties()
 {
    // Concatenate the property values together on three lines.
    label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" +
                  "Checked: " + checkBox1.Checked.ToString() + "\n" +
                  "CheckState: " + checkBox1.CheckState.ToString(); 
    
    // 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;
    }
 }
 

Requirements

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

See Also

CheckBox Class | CheckBox Members | System.Windows.Forms Namespace | ThreeState | CheckState

Show:
© 2014 Microsoft