按钮按键盘键时发生的事件 [英] Button Event to occur when I press a Keyboard key

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

问题描述

我正在创建一个钢琴应用程序,所有键都作为按钮。



当我点击鼠标单击钢琴按钮时,它可以正常工作。



现在,当我按下键盘上的键时,我想要发生同样的事件。

我应该使用什么事件? />


这是按钮点击的事件

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 [ ^ ]事件。



来自 http://stackoverflow.com/a/3334956 [ ^ ]



You have form? Create the KeyDown[^] Event.

From http://stackoverflow.com/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");
    }


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

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