0

我使用下面的代码,试图得到按Ctrl + 小号按一个工具条按钮:多个快捷键

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 

我在这一个新手,所以我不明白百万行的编码,所以你可以保持它尽可能简单:-)。

+0

您是否知道您可以简单地在设计器中分配快捷键组合?否则,问题是什么? – Plutonix

+0

你的问题是什么? – Steve

回答

1

因为没有真正的问题,所以在这里总猜测。首先,为了获得类似的工作,您需要为表单设置KeyPreview = True。接下来,你可能要改用的KeyPressKeyDown事件:

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以某种方式计为多个。

+0

感谢您的回复,但它仍然没有做任何事情。你认为其他解决方案? –

+0

是否存在ToolStripButton20单击事件中的代码?它应该做什么? REAL代码将需要代码中的代码块来代替'...'。将光标放在'ToolStripButton20.PerformClick()'上并按F9,运行该程序,并在按Ctrl + S时查看它是否停止。 – Plutonix

+0

对于click事件的编码,我有:很多编码,除非它不让我插入它。当我按F9键时,它会出现一条红线,表示工具条Button2012 –