Freigeben über


CheckBox.ThreeState-Eigenschaft

Ruft einen Wert ab, der angibt, ob für die CheckBox drei anstelle von zwei Aktivierungszuständen zulässig sind, oder legt diesen fest.

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

Syntax

'Declaration
Public Property ThreeState As Boolean
'Usage
Dim instance As CheckBox
Dim value As Boolean

value = instance.ThreeState

instance.ThreeState = value
public bool ThreeState { get; set; }
public:
property bool ThreeState {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_ThreeState ()

/** @property */
public void set_ThreeState (boolean value)
public function get ThreeState () : boolean

public function set ThreeState (value : boolean)

Eigenschaftenwert

true, wenn die CheckBox drei Aktivierungszustände anzeigen kann, andernfalls false. Der Standardwert ist false.

Hinweise

Wenn die ThreeState-Eigenschaft auf false festgelegt ist, kann der CheckState-Eigenschaftenwert nicht durch Interaktionen des Benutzers, sondern nur im Code auf den Indeterminate-Wert für System.Windows.Forms.CheckState festgelegt werden.

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 Code 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 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