本文介绍了按钮按键盘键时发生的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个钢琴应用程序,所有键都作为按钮。 当我点击鼠标单击钢琴按钮时,它可以正常工作。 现在,当我按下键盘上的键时,我想要发生同样的事件。 我应该使用什么事件? /> 这是按钮点击的事件
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"); }
更多推荐
按钮按键盘键时发生的事件
发布评论