Compartilhar via


CheckBox.ThreeState Propriedade

Definição

Obtém ou define um valor que indica se os CheckBox três estados de verificação permitirão em vez de dois.

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

Valor da propriedade

true se for CheckBox possível exibir três estados de verificação; caso contrário, false. O valor padrão é false.

Exemplos

O exemplo de código a seguir exibe os valores de três propriedades em um rótulo. A ThreeState propriedade alterna entre true e false com cliques alternados do controle e as CheckAlign alternativas entre os valores e MiddleLeft os MiddleRight valores de System.Drawing.ContentAlignment. Este exemplo mostra como os valores da propriedade são alterados à medida que a ThreeState propriedade é alterada e o controle é verificado. Esse código requer que um CheckBox, Label e Button todos foram instanciados em um formulário e que o rótulo é grande o suficiente para exibir três linhas de texto, bem como uma referência ao System.Drawing namespace. Esse código deve ser chamado no Click manipulador de eventos do controle.

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

Comentários

Se a ThreeState propriedade estiver definida como false, o valor da CheckState propriedade só poderá ser definido como o Indeterminate valor do código e não pela interação do System.Windows.Forms.CheckState usuário.

Aplica-se a