热键按钮,在C#Windows应用程序 [英] hotkey to button in C# Windows application

查看:99
本文介绍了热键按钮,在C#Windows应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何做一个热键按钮,在C#Windows应用程序

How do i make a hotkey to button in C# Windows application

推荐答案

覆盖窗体的 ProcessCmdKey 。如果你发现你喜欢一个按键,调用相同的方法该按钮会。

Override Form's ProcessCmdKey. If you find a keystroke that you like, call the same method that the button would.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (keyData == (Keys.Control | Keys.X))
    {
        DoSomething();
        return true;
    }
    return base.ProcessCmdKey(ref msg, keyData);
}

private void button1_Click(object sender, EventArgs e)
{
    DoSomething();
}

private void DoSomething()
{
    MessageBox.Show("hi!");
}

修改:周杰伦的方法,如果你能更好找到一个合适的记忆。

EDIT: Jay's method is better if you can find an appropriate mnemonic.

这篇关于热键按钮,在C#Windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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