在VB.NET中,即使窗体在按下键时最小化或未选中,仍调用函数
我有这个密码:在VB.NET中,即使窗体在按下键时最小化或未选中,仍调用函数,vb.net,function,keydown,topmost,minimized,Vb.net,Function,Keydown,Topmost,Minimized,我有这个密码: Public Sub FuncKeysModule(ByVal value As Keys) 'Check what function key is in a pressed state, and then perform the corresponding action. Select Case value Case Keys.F8 spam.Enabled = True TabControl1.S
Public Sub FuncKeysModule(ByVal value As Keys)
'Check what function key is in a pressed state, and then perform the corresponding action.
Select Case value
Case Keys.F8
spam.Enabled = True
TabControl1.SelectedIndex = 0
state = "Activo"
Case Keys.F9
spam.Enabled = False
TabControl1.SelectedIndex = 1
state = "Parado"
End Select
End Sub
Private Sub frmMain_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyValue = Keys.F1 Or Keys.F2 Or Keys.F3 Or Keys.F4 Or Keys.F5 Or Keys.F6 Or Keys.F7 Or Keys.F8 Or Keys.F9 Or Keys.F10 Or Keys.F11 Or Keys.F12 Then
FuncKeysModule(e.KeyValue)
e.Handled = True
End If
End Sub
当我按F8或F9时,表单调用您可以看到的函数。但是我有一个家伙,如果表单被最小化或未选中(如果我有TopMost on True),我怎么能称之为dode呢
谢谢
我有以下代码:
Public Sub FuncKeysModule(ByVal value As Keys)
'Check what function key is in a pressed state, and then perform the corresponding action.
Select Case value
Case Keys.F8
spam.Enabled = True
TabControl1.SelectedIndex = 0
state = "Activo"
Case Keys.F9
spam.Enabled = False
TabControl1.SelectedIndex = 1
state = "Parado"
End Select
End Sub
Private Sub frmMain_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyValue = Keys.F1 Or Keys.F2 Or Keys.F3 Or Keys.F4 Or Keys.F5 Or Keys.F6 Or Keys.F7 Or Keys.F8 Or Keys.F9 Or Keys.F10 Or Keys.F11 Or Keys.F12 Then
FuncKeysModule(e.KeyValue)
e.Handled = True
End If
End Sub
但每次我运行项目时,都会发生异常,无法设置键盘挂钩
我能做什么S这是可能的,您必须取消选中项目的属性->调试表上的“启用Visual Studio宿主进程”,并使用以下代码:
Public Sub FuncKeysModule(ByVal value As Keys)
'Check what function key is in a pressed state, and then perform the corresponding action.
Select Case value
Case Keys.F8
spam.Enabled = True
TabControl1.SelectedIndex = 0
state = "Activo"
Case Keys.F9
spam.Enabled = False
TabControl1.SelectedIndex = 1
state = "Parado"
End Select
End Sub
Private Sub frmMain_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyValue = Keys.F1 Or Keys.F2 Or Keys.F3 Or Keys.F4 Or Keys.F5 Or Keys.F6 Or Keys.F7 Or Keys.F8 Or Keys.F9 Or Keys.F10 Or Keys.F11 Or Keys.F12 Then
FuncKeysModule(e.KeyValue)
e.Handled = True
End If
End Sub
它的作品:)下面的文章应该能回答你的问题: