CheckBox.Checked Propriedade

Definição

Recebe ou define um valor que indica se o CheckBox está no estado verificado.

public:
 property bool Checked { bool get(); void set(bool value); };
[System.ComponentModel.Bindable(true)]
public bool Checked { get; set; }
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.SettingsBindable(true)]
public bool Checked { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Checked : bool with get, set
[<System.ComponentModel.Bindable(true)>]
[<System.ComponentModel.SettingsBindable(true)>]
member this.Checked : bool with get, set
Public Property Checked As Boolean

Valor de Propriedade

true se o CheckBox estiver no estado verificado; caso contrário, false. O valor predefinido é false.

Nota: Se a ThreeState propriedade for definida para true, a Checked propriedade devolverá true para um Checked ou IndeterminateCheckState.

Atributos

Exemplos

O exemplo de código seguinte apresenta os valores de três propriedades numa etiqueta. A ThreeState propriedade alterna entre true e false com cliques alternados do controlo e os CheckAlign alternam entre um ContentAlignment valor de MiddleRight e MiddleLeft. Este exemplo mostra como os valores das propriedades mudam à medida que a ThreeState propriedade muda e o controlo é verificado. Este exemplo exige que um CheckBox, Label e Button tenham sido todos instanciados num formulário e que o rótulo seja suficientemente grande para mostrar três linhas de texto, bem como uma referência ao System.Drawing namespace. Este código deve ser chamado no Click gestor de eventos do controlo.

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

Observações

Quando o valor é true, a CheckBox parte do controlo apresenta um visto de verificação. Se a Appearance propriedade estiver definida para Button, o controlo aparecerá afundado quando Checked está true e elevado como um botão padrão quando false.

Aplica-se a

Ver também