CheckBox.ThreeState Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Recebe ou define um valor que indica se permitirá CheckBox três estados de verificaçã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 de Propriedade
true se o CheckBox for capaz de mostrar três estados de verificação; caso contrário, false. O valor predefinido é false.
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 as CheckAlign alternâncias entre os MiddleRight valores e MiddleLeft de System.Drawing.ContentAlignment. Este exemplo mostra como os valores das propriedades mudam à medida que a ThreeState propriedade muda e o controlo é verificado. Este código requer 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
Se a propriedade ThreeState for definida para false, o valor da propriedade CheckState só pode ser definido para o valor Indeterminate de System.Windows.Forms.CheckState no código e não pela interação do utilizador.