Freigeben über


CheckBox.CheckState-Eigenschaft

Ruft den Zustand der CheckBox ab oder legt diesen fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
<BindableAttribute(True)> _
Public Property CheckState As CheckState
'Usage
Dim instance As CheckBox
Dim value As CheckState

value = instance.CheckState

instance.CheckState = value
[BindableAttribute(true)] 
public CheckState CheckState { get; set; }
[BindableAttribute(true)] 
public:
property CheckState CheckState {
    CheckState get ();
    void set (CheckState value);
}
/** @property */
public CheckState get_CheckState ()

/** @property */
public void set_CheckState (CheckState value)
public function get CheckState () : CheckState

public function set CheckState (value : CheckState)

Eigenschaftenwert

Einer der CheckState-Enumerationswerte. Der Standardwert ist Unchecked.

Ausnahmen

Ausnahmetyp Bedingung

InvalidEnumArgumentException

Der zugewiesene Wert ist keiner der CheckState-Enumerationswerte.

Hinweise

Wenn die ThreeState-Eigenschaft auf false festgelegt ist, kann der CheckState-Eigenschaftenwert nicht durch Interaktionen des Benutzers, sondern nur im Code auf CheckState.Indeterminate festgelegt werden.

In der folgenden Tabelle wird erläutert, wie die System.Windows.Forms.Appearance des CheckBox-Steuerelements in den verschiedenen Zuständen im Normal-Format und im Button-Format der Steuerelement-CheckBox.Appearance angezeigt wird.

CheckState

Appearance.Normal

Appearance.Button

Checked

Die CheckBox zeigt ein Häkchen an.

Das Steuerelement wird abgesenkt dargestellt.

Unchecked

Die CheckBox ist leer.

Das Steuerelement wird angehoben dargestellt.

Indeterminate

Die CheckBox wird mit einem Häkchen angezeigt und schattiert dargestellt.

Das Steuerelement wird flach dargestellt.

Beispiel

Im folgenden Codebeispiel werden die Werte von drei Eigenschaften in einer Bezeichnung angezeigt. Die ThreeState-Eigenschaft wechselt bei wiederholtem Klicken auf das Steuerelement zwischen true und false, und CheckAlign wechselt zwischen dem MiddleRight-Wert und dem MiddleLeft-Wert für die System.Drawing.ContentAlignment. Dieses Beispiel veranschaulicht, wie sich die Eigenschaftenwerte ändern, wenn die ThreeState-Eigenschaft geändert und das Steuerelement aktiviert wird. In diesem Beispiel wird davon ausgegangen, dass CheckBox, Label und Button in einem Formular instanziiert wurden und die Bezeichnung genügend Platz bietet, um drei Textzeilen sowie einen Verweis auf den System.Drawing-Namespace anzuzeigen. Dieser Code muss im Click-Ereignishandler des Steuerelements aufgerufen werden.

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
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;
    }
 }
 
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()
{
    // Concatenate the property values together on three lines.
    label1.set_Text("ThreeState: " + checkBox1.get_ThreeState() + "\n"
        + "Checked: " + checkBox1.get_Checked() + "\n" 
        + "CheckState: " + checkBox1.get_CheckState());

    //Change the ThreeState and CheckAlign properties on every other click.
    if (!(checkBox1.get_ThreeState())) {
        checkBox1.set_ThreeState(true);
        checkBox1.set_CheckAlign(ContentAlignment.MiddleRight);
    }
    else {
        checkBox1.set_ThreeState(false);
        checkBox1.set_CheckAlign(ContentAlignment.MiddleLeft);
    }
} //AdjustMyCheckBoxProperties
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;
    }
 }
 

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

CheckBox-Klasse
CheckBox-Member
System.Windows.Forms-Namespace
CheckBox.Checked-Eigenschaft
ThreeState