单击后散焦按钮
defocus button after clicking it
在 vb 项目中,我有 3 个按钮(带有按钮外观的复选框)...如果我单击其中的 1 个,它仍然处于选中状态(聚焦),
我会用一个小的 RF 键盘控制那个程序,我很容易按 space 键!
我如何取消选择(松开焦点)该控件以避免按 space 意外激活-停用?
我试过添加一个隐藏按钮,并将其集中在复选按钮的点击事件上”...比如:
newbutton.focus()
但不起作用!后来我尝试聚焦主窗体,但它也不起作用!
form1.focus()
我也试过了:
Form1.select()
但点击(检查)按钮后仍然没有工作,再次点击 space 键可以轻松取消选中!避免意外取消选中的正确方法是什么?
谢谢。
为什么不完全禁用复选框的 SPACE 和 ENTER 键?
'This contains the list of keys that should be disabled from interacting with your check boxes.
'You can add or remove keys from this as you like.
Dim DisabledKeys As New HashSet(Of Keys) From {
Keys.Enter, Keys.Space
}
Private Sub CheckBoxes_KeyDown(sender As Object, e As KeyEventArgs) Handles CheckBox1.KeyDown, CheckBox2.KeyDown, CheckBox3.KeyDown
e.SuppressKeyPress = DisabledKeys.Contains(e.KeyCode)
End Sub
您似乎在使用 WinForm。作为名为 ActiveControl 的 属性 的表单,可以设置为 Nothing
(空)。在 CheckBox.CheckedChanged
处理程序中这样做,将 取消焦点 CheckBox
并防止您遇到的问题。
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
Me.ActiveControl = Nothing
' any other necessary code
End Sub
在 vb 项目中,我有 3 个按钮(带有按钮外观的复选框)...如果我单击其中的 1 个,它仍然处于选中状态(聚焦),
我会用一个小的 RF 键盘控制那个程序,我很容易按 space 键!
我如何取消选择(松开焦点)该控件以避免按 space 意外激活-停用? 我试过添加一个隐藏按钮,并将其集中在复选按钮的点击事件上”...比如:
newbutton.focus()
但不起作用!后来我尝试聚焦主窗体,但它也不起作用!
form1.focus()
我也试过了:
Form1.select()
但点击(检查)按钮后仍然没有工作,再次点击 space 键可以轻松取消选中!避免意外取消选中的正确方法是什么?
谢谢。
为什么不完全禁用复选框的 SPACE 和 ENTER 键?
'This contains the list of keys that should be disabled from interacting with your check boxes.
'You can add or remove keys from this as you like.
Dim DisabledKeys As New HashSet(Of Keys) From {
Keys.Enter, Keys.Space
}
Private Sub CheckBoxes_KeyDown(sender As Object, e As KeyEventArgs) Handles CheckBox1.KeyDown, CheckBox2.KeyDown, CheckBox3.KeyDown
e.SuppressKeyPress = DisabledKeys.Contains(e.KeyCode)
End Sub
您似乎在使用 WinForm。作为名为 ActiveControl 的 属性 的表单,可以设置为 Nothing
(空)。在 CheckBox.CheckedChanged
处理程序中这样做,将 取消焦点 CheckBox
并防止您遇到的问题。
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
Me.ActiveControl = Nothing
' any other necessary code
End Sub