【问题标题】:Hotkey not working on form load热键不适用于表单加载
【发布时间】:2013-08-23 11:39:01
【问题描述】:

我有一个类来注册/取消注册热键。当应用程序以 Form Load 事件启动时,它可以完美运行。

private Hotkey myHotKey;
private IntPtr thisWindow;
    private void Form1_Load(object sender, EventArgs e)
      {
          thisWindow = FindWindow(null, "Form1");
          myHotKey = new Hotkey(thisWindow);
          myHotKey.RegisterHotKeys();

      }

现在的问题是我想在启动时将应用程序隐藏在系统托盘中,但它没有注册我的主机密钥,当我运行下面的代码时,它成功显示我 Notify() 并且除了我的热键之外的其他内容无效。:

public Form1()
{
    InitializeComponent();
    notifyIcon1.ContextMenuStrip = contextMenuStrip1;
    notifyIcon1.Click += notifyIcon1_Click;
    notifyIcon1.DoubleClick += notifyIcon1_DoubleClick;
    openToolStripMenuItem.Click += openToolStripMenuItem_Click;
    exitToolStripMenuItem.Click += exitToolStripMenuItem_Click;
    Notify("Application Name", "Application Started...", 1000);
    thisWindow = FindWindow(null, "Form1");
    myHotKey = new Hotkey(thisWindow);
    myHotKey.RegisterHotKeys();
}

请您指导我做错了什么。谢谢

【问题讨论】:

标签: c# registerhotkey


【解决方案1】:

感谢大家的帮助,我遇到了这个例子,它以更好的方式解释了一切:

http://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html

hotkey = new GlobalHotkeys();
hotkey.RegisterGlobalHotKey( (int) Keys.F11, GlobalHotkeys.MOD_CONTROL, this.Handle);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    • 2018-06-10
    • 1970-01-01
    • 2019-05-29
    • 2021-11-08
    • 2021-10-24
    相关资源
    最近更新 更多