多个键盘快捷键 [英] Multiple Keyboard Shortcuts
问题描述
我正在使用以下代码尝试使 Ctrl + S 按下工具栏按钮:
I am using the following code to try and get Ctrl+S to press a toolstrip button:
Private Sub take_register_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.S And Keys.Control Then
ToolStripButton20.PerformClick()
End If
End Sub
我是新手,所以我不懂数百万行的编码,所以请您尽量保持简单:-).
I am a newbie at this, so I dont understand millions of lines of coding, so can you please keep it as simple as possible :-) .
推荐答案
由于没有实际的问题,因此此处的总猜测量.首先,为了获得类似的工作,您需要为表单设置KeyPreview = True
.接下来,您可能要使用KeyDown
事件而不是KeyPress
:
Total guesswork here since there is no actual question. First, in order to get something like that work, you need to set KeyPreview = True
for the form. Next, you probably want to use the KeyDown
event instead of KeyPress
:
Private Sub Form1_KeyDown(...)
' when possible use AndAlso for speed and to avoid some errors in
' some situations. if e.Control is False, the second part wont be evaluated.
If e.Control AndAlso e.KeyCode = Keys.S Then
ToolStripButton20.PerformClick()
End If
End Sub
要重复:您可以在设计器中简单地将快捷键组合分配给菜单对象,然后让.NET完成所有工作. ...而且除非 Ctrl + S 以某种方式计为倍数,否则我不知道多重"会出现在哪里.
To repeat: you can simply assign a shortcut key combo to the menu object in the designer and let .NET do all the work. ...and I don't know where "multiple" comes in to play unless Ctrl+S counts as multiple somehow.
这篇关于多个键盘快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!