【问题标题】:ProcessCmdKey after closing application关闭应用程序后的 ProcessCmdKey
【发布时间】:2012-09-05 19:24:56
【问题描述】:

如果我按下 Ctrl+ACtrl+ProcessCmdKey 有这个功能,它将运行一些按钮kbd>N,或 Ctrl+S.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (keyData == (Keys.Control | Keys.N))
    {
        button4_Click(this, null);
        return true;
    }

    if (keyData == (Keys.Control | Keys.A))
    {
        button3_Click(this, null);
        return true;
    }

    if (keyData == (Keys.Control | Keys.S))
    {
        label10_Click(this, null);
        return true;
    }

    return base.ProcessCmdKey(ref msg, keyData);
}

我有一个问题,是否可以在关闭应用程序(不是关闭应用程序)后,使用Form_Closing 将应用程序放入System Icons 使用notifyIcon,如果你会按Ctrl kbd>+A(例如),会运行按钮吗?

现在它不起作用,但我可以这样做吗?

【问题讨论】:

  • 没有。在搜索框或谷歌查询中输入“RegisterHotKey”。

标签: c# keypress keydown notifyicon


【解决方案1】:

要设置托盘图标,请参阅guide

您可以通过 Project Properties > Application > Icon 设置项目的图标。

您可以像这样从任务栏中隐藏窗口:

this.ShowInTaskbar = false;

此代码将阻止表单关闭并将其隐藏(除非窗口正在关闭)。

protected override void OnFormClosing(FormClosingEventArgs e)
{
    base.OnFormClosing(e);

    if (e.CloseReason == CloseReason.WindowsShutDown) 
    {
        return;
    }

    e.Cancel = true;

    this.WindowState = FormWindowState.Minimized
}

此代码将为您提供托盘图标并在双击时重新显示表单。

    public MyForm()
    {
        InitializeComponent();

        NotifyIcon trayIcon = new NotifyIcon()
        {
            Icon = new Icon(@"C:\Temp\MyIcon.ico"),
            BalloonTipText = "Open Me!",
            Visible = true
        };

        trayIcon.DoubleClick += new EventHandler(trayIcon_DoubleClick);
    }

    public void trayIcon_DoubleClick(object sender, EventArgs e)
    {
        this.ShowInTaskbar = false;
        this.WindowState = FormWindowState.Normal;
    }

【讨论】:

  • 我知道这个并且我做了这个,但是我想知道我是否可以在关闭应用程序后使用 ProcessCmdKey!
  • 在这种情况下不,至少在没有挂钩 Windows 事件的情况下不会。
猜你喜欢
  • 2014-06-06
  • 1970-01-01
  • 2021-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-10
  • 1970-01-01
相关资源
最近更新 更多