CheckBox.ThreeState Egenskap

Definition

Hämtar eller anger ett värde som anger om CheckBox tillåter tre kontrolltillstånd i stället för två.

public:
 property bool ThreeState { bool get(); void set(bool value); };
public bool ThreeState { get; set; }
member this.ThreeState : bool with get, set
Public Property ThreeState As Boolean

Egenskapsvärde

true CheckBox om kan visa tre kontrolltillstånd, annars . false Standardvärdet är false.

Exempel

I följande kodexempel visas värdena för tre egenskaper i en etikett. Egenskapen ThreeState växlar mellan true och false med alternerande klick i kontrollen och CheckAlign växlar mellan MiddleRight värdena MiddleLeftoch System.Drawing.ContentAlignment för . Det här exemplet visar hur egenskapsvärdena ändras när ThreeState egenskapen ändras och kontrollen kontrolleras. Den här koden kräver att en CheckBox, Label och Button alla har instansierats i ett formulär och att etiketten är tillräckligt stor för att visa tre textrader samt en referens till System.Drawing namnområdet. Den här koden ska anropas i Click händelsehanteraren för kontrollen.

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

Kommentarer

Om egenskapen ThreeState är inställd på false kan egenskapsvärdet CheckState endast anges till värdet Indeterminate för System.Windows.Forms.CheckState i kod och inte av användarinteraktion.

Gäller för