CheckBox.ThreeState 属性

定义

获取或设置一个值,该值指示此 CheckBox 是否允许三种复选状态而不是两种。

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

属性值

如果 CheckBox 可以显示三种复选状态,则为 true;否则为 false。 默认值是 false

示例

下面的代码示例显示标签中三个属性的值。 属性ThreeState在 和 false 之间true交替单击控件CheckAlign,在 和 MiddleLeftSystem.Drawing.ContentAlignment之间MiddleRight交替单击。 此示例演示属性值如何随着 ThreeState 属性更改和控件的检查而更改。 此代码要求 CheckBoxLabelButton 都已在窗体上实例化,并且标签足够大,以显示三行文本,以及对 命名空间的 System.Drawing 引用。 应在 控件的 Click 事件处理程序中调用此代码。

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

注解

如果 属性 ThreeState 设置为 false,则 CheckState 属性值只能在代码中设置为 Indeterminate 的值, System.Windows.Forms.CheckState 而不能通过用户交互。

适用于