Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net Ctrl+;班次+;使用Me.KeyDown无法检测到H_Vb.net - Fatal编程技术网

Vb.net Ctrl+;班次+;使用Me.KeyDown无法检测到H

Vb.net Ctrl+;班次+;使用Me.KeyDown无法检测到H,vb.net,Vb.net,按下Ctrl+Shift+H期间不起反应的代码: Private Sub HideMode(ByVal sendeer As System.Object, ByVal e As KeyEventArgs) Handles Me.KeyDown Select Case CInt(e.KeyCode) Case Keys.ControlKey If e.Shift AndAlso e.KeyValue = Convert.ToInt32(Convert

按下Ctrl+Shift+H期间不起反应的代码:

Private Sub HideMode(ByVal sendeer As System.Object, ByVal e As KeyEventArgs) Handles Me.KeyDown
    Select Case CInt(e.KeyCode)
        Case Keys.ControlKey
            If e.Shift AndAlso e.KeyValue = Convert.ToInt32(Convert.ToChar(Keys.H)) Then
                MsgBox("Test hide function")
            End If
    End Select
End Sub
预期结果是,按下Ctrl+Shift+H后,将显示一个
msgbox
文本“Test hide function”


这里的错误是什么?

我不明白为什么要尝试将KeyCode转换为整数,而使用Keys enum可以轻松完成相同的工作

Select Case e.KeyCode
    Case Keys.H
        If (e.Control AndAlso e.Shift) Then 
            MsgBox("Test hide function")
        End If
End Select
编辑嗯,WebBrowser控件是另一个野兽。您需要为它添加一个特定的KeyDown处理程序(当焦点在其他控件上时,另一个处理KeyDown的处理程序除外)


您是否将表单KeyPreview设置为True?似乎您希望为表单而不是文本框处理向下键。这需要使用表单设计器将该属性设置为true,我应该在哪里设置它。它是形式本身的属性。你需要它,否则键会转到当前焦点控件的KeyDown事件,而看起来你需要在formNo上进行全局捕获,我仍然不能使用它。还有其他方法可以检查Ctrl+Shift+H吗?当我按下Ctrl+Shift+H时,没有发生任何事情。如果您有其他方法,为什么不在答案中显示它(您所说的是
转到当前聚焦控件的按键事件,而您似乎需要对表单进行全局捕获
),我真的不明白。
Private Sub Browser_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles WebBrowser1.PreviewKeyDown
    Select Case e.KeyCode
        Case Keys.H
            If e.Shift AndAlso e.Control Then
                MsgBox("Test hide function")
            End If
    End Select
End Sub