C#键盘事件处理

编程入门 行业动态 更新时间:2024-10-28 00:25:39
本文介绍了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#键盘事件处理

本文发布于:2023-11-08 10:47:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569174.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:键盘   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!