添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
  • Click 事件处理程序中,使用 Checked 属性来确定控件的状态,并执行任何必要的操作。

    Private Sub CheckBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.Click  
       ' The CheckBox control's Text property is changed each time the
       ' control is clicked, indicating a checked or unchecked state.  
       If CheckBox1.Checked = True Then  
          CheckBox1.Text = "Checked"  
          CheckBox1.Text = "Unchecked"  
       End If  
    End Sub  
    
    private void checkBox1_Click(object sender, System.EventArgs e)  
       // The CheckBox control's Text property is changed each time the
       // control is clicked, indicating a checked or unchecked state.  
       if (checkBox1.Checked)  
          checkBox1.Text = "Checked";  
          checkBox1.Text = "Unchecked";  
    
    private:  
       void checkBox1_CheckedChanged(System::Object ^ sender,  
          System::EventArgs ^ e)  
          if (checkBox1->Checked)  
             checkBox1->Text = "Checked";  
             checkBox1->Text = "Unchecked";  
    

    如果用户尝试双击 CheckBox 控件,将分别处理每次单击;也就是说,CheckBox 控件不支持双击事件。

    AutoCheck 属性为 true(默认值)时,单击 CheckBox 时会自动选择或清除它。 否则,必须在发生 Click 事件时手动设置 Checked 属性。

    还可以使用 CheckBox 控件来确定操作过程。

    确定单击复选框时的操作过程

  • 使用 case 语句查询 CheckState 属性的值以确定操作过程。 当 ThreeState 属性设置为 true 时,CheckState 属性可能返回三个可能的值,表示该框处于选中状态、该框处于未选中状态或第三种不确定状态(框在这种状态下灰显,表示该选项不可用)。

    Private Sub CheckBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.Click  
       Select Case CheckBox1.CheckState  
          Case CheckState.Checked  
             ' Code for checked state.  
          Case CheckState.Unchecked  
             ' Code for unchecked state.  
          Case CheckState.Indeterminate  
             ' Code for indeterminate state.  
       End Select
    End Sub  
    
    private void checkBox1_Click(object sender, System.EventArgs e)  
       switch(checkBox1.CheckState)  
          case CheckState.Checked:  
             // Code for checked state.  
             break;  
          case CheckState.Unchecked:  
             // Code for unchecked state.  
             break;  
          case CheckState.Indeterminate:  
             // Code for indeterminate state.  
             break;  
    
    private:  
       void checkBox1_CheckedChanged(System::Object ^ sender,  
          System::EventArgs ^ e)  
          switch(checkBox1->CheckState) {  
             case CheckState::Checked:  
                // Code for checked state.  
                break;  
             case CheckState::Unchecked:  
                // Code for unchecked state.  
                break;  
             case CheckState::Indeterminate:  
                // Code for indeterminate state.  
                break;  
    

    ThreeState 属性设置为 true 时,Checked 属性为 CheckedIndeterminate 返回 true

  • CheckBox
  • CheckBox 控件概述
  • 如何:使用 Windows 窗体 CheckBox 控件设置选项
  • CheckBox 控件
  •