帮助为VB程序创建自定义键盘快捷键 [英] Help creating custom keyboard shortcuts for VB program

查看:182
本文介绍了帮助为VB程序创建自定义键盘快捷键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我在为我的程序创建自定义键盘快捷方式时遇到了一些麻烦。我有2种形式(frmMain和frmSelect)。我试图获得CRTL + S的快捷方式从frmMain打开frmSelect。



这是我想我会尝试的,但表格没有打开当我按下CRTL和S.



Hello everyone. I am having a little trouble getting a custom keyboard shortcut made for my program. I have 2 forms (frmMain and frmSelect). I am trying to get a shortcut of CRTL+S to open up frmSelect from frmMain.

This is what I thought I would try, but the form is not opening up when I press CRTL and S.

Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.ControlKey + Keys.S Then
            frmSearch.Show()
        End If
    End Sub





任何帮助都非常感谢....

推荐答案

原油但是有效的方法是创建一个菜单栏,将其可见属性设置为 False 。然后,添加所有命令,为它们编写代码并分配所需的快捷方式。
A crude but effective method is to create a menu bar, set its Visible property to False. Then, add all your commands, write code for them and assign the desired shortcuts.


它与代码的处理有关。如果您将Keys.S(值为83)添加到ControlKey,其值为17.您最终会得到100,这对应于数字键盘上的4。如果你在小键盘上点击4,你的第二个表格就会打开。



为了防止这种情况发生,请试试这个。通过检查布尔值,您可以确保键码符合您的意思。



It has to do with the handling of the codes. If you added "Keys.S", which is given a value of 83 to "ControlKey", which has a value of 17. You would end up with 100, which corresponds to "4" on the Number Pad. If you hit "4" on the numpad, your second form will open.

To keep this from happening, try this instead. By checking the boolean values, you make sure that the keycode is what you meant it to be.

Private Sub frmMain_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    If e.KeyCode = Keys.S And e.Control = True Then
        frmSearch.Show()
    End If
End Sub


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    'Trace Control + Key Event in VB6.0 
    '===========================================================
    If KeyCode = Asc("F") And Shift = 2 Then
        Call Command8_Click
    ElseIf KeyCode = Asc("D") And Shift = 2 Then
        Call Command9_Click
    ElseIf KeyCode = Asc("M") And Shift = 2 Then
        Call Command10_Click
    ElseIf KeyCode = Asc("P") And Shift = 2 Then
        Call Command11_Click
    ElseIf KeyCode = Asc("M") And Shift = 2 Then
        Call Check1_Click
    End If
    '===========================================================
End Sub




'VALUES FOR Shift  KEYS
'=====================================================
				  'SHIFT KEY = 1	
				  'CTRL KEY = 2
				  'CTRL + SHIFT KEY = 3
				  'ALT KEY = 4
				  'ALT+SHIFT KEY = 5
				  'CTRL+ALT KEY = 6
				  'ATRL+SHIFT+ALTER KEY = 7


这篇关于帮助为VB程序创建自定义键盘快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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