CheckBox.ThreeState プロパティ

定義

CheckBox で 2 つではなく 3 つのチェックの状態が表示できるかどうかを示す値を取得または設定します。

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 が 3 つのチェックの状態を表示できる場合は true。それ以外の場合は false。 既定値は false です。

次のコード例では、ラベルに 3 つのプロパティの値を表示します。 プロパティは と を交互に切り替え、コントロールを交互にCheckAlignクリックし、 と の値を交互にMiddleLeftSystem.Drawing.ContentAlignmentMiddleRightクリックします。truefalseThreeState この例では、プロパティが変更され、コントロールが ThreeState チェックされるときにプロパティ値がどのように変化するかを示します。 このコードでは、 CheckBoxLabelButton がすべてフォームでインスタンス化されており、ラベルが 3 行のテキストと名前空間への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

注釈

プロパティが ThreeStatefalse設定されている場合、プロパティ値CheckStateはコード内の のIndeterminateSystem.Windows.Forms.CheckState値にのみ設定でき、ユーザーの操作では設定できません。

適用対象