0

如果我按下+ 、或+或+ ,我有这个功能ProcessCmdKey将运行一些按钮。CtrlACtrlNCtrlS

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 Iconsusing notifyIcon,如果您按Ctrl+ A(例如),将运行按钮?

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

4

1 回答 1

1

要设置托盘图标,请参阅本指南

您可以通过 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;
    }
于 2012-09-05T19:45:17.323 回答