C#键盘事件处理 [英] C# Keyboard event handling

查看:113
本文介绍了C#键盘事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮数组,每个按钮都带有一个单击的事件处理程序((使用(按钮)发送程序进行编程)).我想以这样的方式使用键盘,即所按下的键与单击按钮时的作用相同!
如何在不重写事件的情况下执行此操作? (看到按钮单击是一个事件处理程序,而按下按键是一个键事件处理程序).

I Have an array of buttons with an event handler on click for each button ((programmed using (Button) sender )). I want to use the keyboard in such way that the key pressed do the same thing as if a button was clicked!
How to do this without rewriting the event? (seeing that the button click is an eventhandler and the key press is a keyeventhandler)

推荐答案

创建一些实现该操作的方法,并从不同的事件处理程序中调用if和if .是的,不要使用Designer,而是将所有事件处理程序添加到代码中的事件调用列表("+ ="运算符)中.

—SA
Create some method implementing the action and call if and call if from different event handler. And yes, don''t use Designer, add all event handlers to event invocation list ("+=" operator) in code.

—SA


浏览此-

keyboard-keys-visual-basic-net [ ^ ]
Go through this-

keyboard-keys-visual-basic-net[^]


如果您不介意使用组合键,请尝试将快捷键映射到按钮.
为此,只需在按钮的标题中放入amersand(&").这将使下一个字母对"Alt" +字母作出反应.

例如.如果您有一个按钮"Do Something",则将其标题设置为"Do So&mething",然后按"ALT" +"M"即可.
If you don''t mind using a combination of keys, try mapping shortcut keys to the buttons.
To do so, just put an amersand ("&") in the button''s caption. That will make the next letter to react to "Alt" + Letter.

E.g. if you have a button "Do Something", make it''s caption "Do So&mething" and it will get pressed by "ALT" + "M".


这篇关于C#键盘事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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