在C#中添加F5热键 [英] Adding an F5 Hotkey in C#

查看:402
本文介绍了在C#中添加F5热键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Windows应用程序(WinForms),并希望我的应用程序在用户按下F5时调用一个方法-无论用户在做什么,它都可以工作,但是他们必须使用该程序-我不想使用全局挂钩-有什么想法吗?

I'm making a windows app (WinForms) and would like my application to call a method when the user presses F5 - this should work no matter what the user is doing but they must be using the program - I don't want to use global hooks - any ideas?

推荐答案

覆盖表单的

Override the form's ProcessCmdKey on your main form and look for F5.

protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
{
    bool bHandled = false;
    // switch case is the easy way, a hash or map would be better, 
    // but more work to get set up.
    switch (keyData)
    {
        case Keys.F5:
            // do whatever
            bHandled = true;
            break;
    }
    return bHandled;
}

这篇关于在C#中添加F5热键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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