CheckBox.ThreeState 属性

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

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property ThreeState As Boolean
用法
Dim instance As CheckBox
Dim value As Boolean

value = instance.ThreeState

instance.ThreeState = value
public bool ThreeState { get; set; }
public:
property bool ThreeState {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_ThreeState ()

/** @property */
public void set_ThreeState (boolean value)
public function get ThreeState () : boolean

public function set ThreeState (value : boolean)

属性值

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

备注

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

示例

下面的代码示例将在一个标签中显示三个属性的值。连续单击该控件会使 ThreeState 属性交替设置为 truefalse,而 CheckAlign 会交替设置为 System.Drawing.ContentAlignmentMiddleRightMiddleLeft 值。此示例显示属性值如何在更改 ThreeState 属性和选中该控件时发生更改。此代码要求 CheckBoxLabelButton 已全部在窗体上实例化,并且标签的大小足以显示三行文本和对 System.Drawing 命名空间的引用。应当在该控件的 Click 事件处理程序中调用此代码。

Private Sub AdjustMyCheckBoxProperties()
    ' 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()
    
    ' 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
End Sub 'AdjustMyCheckBoxProperties
private void AdjustMyCheckBoxProperties()
 {
    // Concatenate the property values together on three lines.
    label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" +
                  "Checked: " + checkBox1.Checked.ToString() + "\n" +
                  "CheckState: " + checkBox1.CheckState.ToString(); 
    
    // 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()
   {
      // 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()
{
    // Concatenate the property values together on three lines.
    label1.set_Text("ThreeState: " + checkBox1.get_ThreeState() + "\n"
        + "Checked: " + checkBox1.get_Checked() + "\n" 
        + "CheckState: " + checkBox1.get_CheckState());

    //Change the ThreeState and CheckAlign properties on every other click.
    if (!(checkBox1.get_ThreeState())) {
        checkBox1.set_ThreeState(true);
        checkBox1.set_CheckAlign(ContentAlignment.MiddleRight);
    }
    else {
        checkBox1.set_ThreeState(false);
        checkBox1.set_CheckAlign(ContentAlignment.MiddleLeft);
    }
} //AdjustMyCheckBoxProperties
private function AdjustMyCheckBoxProperties()
 {
    // Concatenate the property values together on three lines.
    label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" +
                  "Checked: " + checkBox1.Checked.ToString() + "\n" +
                  "CheckState: " + checkBox1.CheckState.ToString(); 
    
    // 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;
    }
 }
 

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

CheckBox 类
CheckBox 成员
System.Windows.Forms 命名空间