使用键盘快捷键从系统托盘最大化 C# 应用程序 [英] Maximize C# Application from System Tray using Keyboard Shortcut

查看:46
本文介绍了使用键盘快捷键从系统托盘最大化 C# 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否可以知道是否可以使用键盘快捷键而不是单击它来从系统托盘最大化我的 Windows 窗体应用程序?

Can I know if there is anyway that I can maximise my windows form application from the system tray using say a Keyboard Shortcut rather than clicking on it?

我目前正在尽量减少使用这段代码

I am currently minimizing using this piece of code

//Minimize to Tray with over-ride for short cut
private void MinimiseToTray(bool shortCutPressed)
{
    notifyIcon.BalloonTipTitle = "Minimize to Tray App";
    notifyIcon.BalloonTipText = "You have successfully minimized your app.";

    if (FormWindowState.Minimized == this.WindowState || shortCutPressed)
    {
        notifyIcon.Visible = true;
        notifyIcon.ShowBalloonTip(500);
        this.Hide();
    }
    else if (FormWindowState.Normal == this.WindowState)
    {
        notifyIcon.Visible = false;
    }
}

因此,我需要一个可以最大化它的键盘快捷键.非常感谢!

Hence, I need a keyboard shortcut that should maximize it. Much thanks!

推荐答案

如果您只是想保留一个组合键"来在您的应用程序上执行某些操作,一个低-级别键盘钩子,您可以看到每个按键都进入任何其他应用程序,这不仅是一种矫枉过正,而且是不好的做法,在我个人看来,可能会让人们认为您在记录键盘!坚持使用热键!

If you simply want to 'reserve a key combination' to perform something on your application, a Low-Level keyboard hook whereby you see every keypress going to any other application is not only an overkill, but bad practice and in my personal view likely to have people thinking that you're keylogging! Stick to a HOT-KEY!

鉴于您的图标没有键盘焦点,您需要注册一个全局键盘热键.

Given that your icon will not have keyboard focus, you need to register a global keyboard hotkey.

其他类似问题:

全球热键与 .NET 的示例:

Hotkey hk = new Hotkey();
hk.KeyCode = Keys.1;
hk.Windows = true;
hk.Pressed += delegate { Console.WriteLine("Windows+1 pressed!"); };

if (!hk.GetCanRegister(myForm))
{ 
    Console.WriteLine("Whoops, looks like attempts to register will fail " +
                      "or throw an exception, show error to user"); 
}
else
{ 
    hk.Register(myForm); 
}

// .. later, at some point
if (hk.Registered)
{ 
   hk.Unregister(); 
}

这篇关于使用键盘快捷键从系统托盘最大化 C# 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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