问题描述
给出
Dim cb As CheckBox = New CheckBox
AddHandler cb, AddressOf cb_CheckChanged
cb.Checked = True
...除了禁用控件外,如何防止分配给Checked引发CheckChanged事件?我在MFC中长大,只有在U S E R更改控件的状态时才会引发事件。 Softy在想什么?真的不可能区分用户事件和我自己的赋值语句事件吗? 赞!
...aside from disabling the control, how can I prevent the assignment to Checked from raising the CheckChanged event? I grew up in MFC and events only got raised when the U S E R changed the control's state. What was Softy was thinking? Is it really impossible to distinguish between an event from the user and an event from my own assignment statement? Yikes!
推荐答案
无论引发事件的原因是什么,引发事件都是完全有效的 CheckChanged
事件仅告诉您 Checked
属性何时更改。
it is perfectly valid to raise the event regardless of the thing causing the event because the CheckChanged
event just tells you when the Checked
property has changed.
如果要避免无限循环,则必须尝试添加条件:
If you are trying to avoid the infinite loop you must be experiencing try adding a conditional:
If Not cb.Checked Then
cb.Checked = True
End If
这篇关于如何防止CheckBox.Checked的赋值语句引发CheckChanged事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!