在CheckBox上触发了错误的事件

时间:2014-04-16 18:25:02

标签: vb.net checkbox

我有两个CheckBoxes,代码如下

Private Sub MasiveModeCkB_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MasiveModeCkB.CheckedChanged
    If MasiveModeCkB.Checked Then
        SendCommandsChkB.Checked = True
        SendCommandsChkB.Enabled = False
    Else
        SendCommandsChkB.Checked = False
        SendCommandsChkB.Enabled = True
    End If
End Sub

Private Sub SendCommandsChkB_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendCommandsChkB.CheckedChanged
    DummyCount += 1

End Sub

我遇到的问题是,当我检查SendCommand时,两个CheckedChanged都被触发,我不明白为什么? 正如您在上面的代码中看到的,我不会在SendCommandsChkB_CheckedChanged中更改MasiveModeCkB的状态。那么为什么要拍摄事件MasiveModeCkB_CheckedChanged?

1 个答案:

答案 0 :(得分:1)

复制代码时不会发生这种情况。有几种可能性:

  1. DummyCount可能未正确初始化,或者可能导致修改MasiveModeCkB设置。
  2. 您可能会将复选框名称和标签混淆。
  3. 设计师可能会混淆一些东西。
  4. 一个。尝试清除表单上的复选框,然后在设计器中再次添加它们。如果以编程方式添加它们,请检查名称和标签。

    B中。在DummyCount += 1处设置一个断点并从那里单步执行以查看正在发生的情况。

相关问题