vb.net 组合键 [英] vb.net key combination

查看:39
本文介绍了vb.net 组合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的 VB.net 应用程序中捕获两次按键,对于这个例子 CTRL + B,下面的代码不起作用,但它对单个键起作用.我试过将 keypreview 设置为 true 但这没有效果.

I'm trying to capture two key presses in my VB.net application, for this example CTRL + B, the code below doesn't work but it does for single keys. I have tried setting keypreview as true but this has no effect.

  Private Sub main_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles mybase.KeyDown
            If e.KeyCode = Keys.ControlKey And e.KeyCode = Keys.B Then
                MsgBox("CTRL + B Pressed !")
            End If
        End Sub
    End Class

谢谢

推荐答案

Control 键是一个修饰键.此代码测试 Ctrl + B

The Control key is a Modifier key. This code tests for Ctrl + B

e.KeyCode = Keys.B AndAlso e.Modifiers = Keys.Control

键码是 B,但修饰符是 Ctrl.

The key-code is B, but the modifier is Ctrl.

您的代码片段,已更新:

Your code snippet, updated:

Private Sub main_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles mybase.KeyDown
    If (e.KeyCode = Keys.B AndAlso e.Modifiers = Keys.Control) Then
        MsgBox("CTRL + B Pressed !")
    End If
End Sub

这篇关于vb.net 组合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆