VB.NET中如何制作快捷键
我想通过为我的特定程序定义的快捷方式运行特定代码。例如,如果我单击 F1 或 Ctrl+C 那么我希望我的程序显示客户列表。我已经使用以下代码尝试了表单的 keydown 事件
If e.KeyCode = Keys.F1 Then
Form6.button4.performclick()
End If
但这似乎不起作用。有人能帮我吗?
我在 Visual Studio 2005 中使用 vb.net 来开发我的应用程序
I want to run specific code through shortcuts defined for my specific program. For example if I click F1 or Ctrl+C then I want my program to show customers list. I have tried form's keydown event with following code
If e.KeyCode = Keys.F1 Then
Form6.button4.performclick()
End If
But this doesn't seem to work. Can anyone help me in this?
I'm using vb.net in visual studio 2005 to develop my application
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
试试这个:
来源
不过,您最好创建自己的事件并引发它而不是引发按钮的单击事件。
Try this:
Source
Although, you'd be better to create your own event and raise that instead of raising the button's click event.
“访问键是菜单、菜单项或按钮等控件标签文本中带下划线的字符。使用访问键,用户可以通过按 ALT 键与例如,如果按钮运行一个打印表单的过程,因此其 Text 属性设置为“Print”,则在字母“P”之前添加“&”会导致字母“P”在下面划线。用户可以在运行时运行按钮文本。通过按 ALT+P 与按钮关联的命令 对于无法接收焦点的控件,您无法使用访问键。”
<一href="http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0CC8QFjAB&url=http://msdn .microsoft.com/en -us/library/bbd5w3b8%28v=vs.85%29.aspx&ei=Or45T6vDCYXhtgeMr5z1Cg& ;usg=AFQjCNFVoyUOFouX2zP2w6IpD8vCywDcbQ&sig2=AoWGhxOgxcVB2zgp16kypQ" rel="nofollow">访问键
尝试访问键吗?
"An access key is an underlined character in the text of a menu, menu item, or the label of a control such as a button. With an access key, the user can "click" a button by pressing the ALT key in combination with the predefined access key. For example, if a button runs a procedure to print a form, and therefore its Text property is set to "Print," adding an ampersand before the letter "P" causes the letter "P" to be underlined in the button text at run time. The user can run the command associated with the button by pressing ALT+P. You cannot have an access key for a control that cannot receive focus."
Access Keys
Try access keys?
这是一个非常简单的方法来完成类似的事情:
不过这是 2010 年的。
Here is a very simple way to do something like that:
This is from 2010 though.
如何在 Visual Studio .NET 中捕获快捷键 那里有一些 VB 示例。
How to Capture Shortcut Keys in Visual Studio .NET There are some VB examples there.
我更喜欢通过为快捷方式添加菜单来实现快捷方式,为每个快捷方式添加菜单项,然后将快捷方式绑定到菜单项。这很好,因为它记录了可用的快捷方式并使编码变得非常简单。
I prefer to implement shortcuts by adding a menu for your shortcuts, add menu items for each shortcut, and then bind the shortcut to the menu items. This is nice because it documents the available shortcuts and makes the coding very simple.
您的代码是正确的,但您应该在表单中设置
keyPreview = true
Your code is correct but you should set
keyPreview = true
in your Form我看到列出的答案,这已经很旧了,但试试这个。热键设置为 alt+d 或 alt+c,如图所示。他们给你的代码和我给你的代码之间的区别在于,即使应用程序最小化,它也能工作。
I saw the answers listed and this is quite old but try this. The hotkeys are set as alt+d or alt+c as indicated. This difference in code between what they are giving you and what i am giving you is that this works even when the application is minimized.
我遇到过同样的情况,我使用了menustrip并指定了快捷键,并使用了performclick功能并将menustrip的属性设置为visible false,它工作得很好。
I have encounterd with same situation, I used menustrip and asigned shortkeys and used performclick function and set the property of menustrip to visible false and it worked fine.