按钮按键盘键时发生的事件

编程入门 行业动态 更新时间:2024-10-27 05:30:29
本文介绍了按钮按键盘键时发生的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建一个钢琴应用程序,所有键都作为按钮。 当我点击鼠标单击钢琴按钮时,它可以正常工作。 现在,当我按下键盘上的键时,我想要发生同样的事件。 我应该使用什么事件? /> 这是按钮点击的事件

I am creating a Piano Application with all the keys as buttons. It works when i click the Piano button using mouse click. Now, I want the same event to occur when i press a key in the keyboard. What event should I use ? This is the event for the button click

private void button1_Click(object sender, EventArgs e) { MessageBox.Show("A"); Beep(349, 150); }

现在我希望当我点击 时会发生同样的过程键盘上的A键。 我知道它的某些事件。但我找不到它。 我应该如何继续实现它?我应该如何实现呢? 提前谢谢

Now I want the same process to happen when i click the "A" key in my keyboard. I know its some event. But I couldn't find it. How should I proceed to achieve it ? And how should i implement it ? Thanks in advance

推荐答案

你有表格吗?创建 KeyDown [ ^ ]事件。 来自 stackoverflow/a/3334956 [ ^ ] You have form? Create the KeyDown[^] Event. From stackoverflow/a/3334956[^] public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.BringToFront(); this.Focus(); this.KeyPreview = true; this.KeyDown += new KeyEventHandler(Form1_KeyDown); } void Form1_KeyDown(object sender, KeyEventArgs e) { Console.WriteLine("test"); }

更多推荐

按钮按键盘键时发生的事件

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

发布评论

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

>www.elefans.com

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