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 替代,並以 控制項的替代點選,以及 CheckAlignMiddleRightMiddleLeftSystem.Drawing.ContentAlignment 之間的替代專案。 本範例示範屬性值在屬性變更時 ThreeState 如何變更,並檢查控制項。 此程式碼需要 CheckBox 在表單上具現化 , LabelButton 而且標籤夠大,足以顯示三行文字,以及命名空間的 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 ,而不是由使用者互動。

適用於