0

I have this function for the ProcessCmdKey that will run some buttons if I will press Ctrl+A, or Ctrl+N, or 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);
}

I have a question, can it be done that after closing the application (not shutdown app), using Form_Closing to put the app in System Icons using notifyIcon, if you will press Ctrl+A (for example), will run the button?

Right now it doesn't work, but can I do this?

Adi Lester
  • 24,731
  • 12
  • 95
  • 110
AnDr3yy
  • 239
  • 2
  • 5
  • 16

1 Answers1

1

To set the tray icon see this guide.

You can set the icon of your project via Project Properties > Application > Icon.

You can hide the window from the task bar like this:

this.ShowInTaskbar = false;

This code will stop a form from closing and just hide it (unless windows is shutting down).

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

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

    e.Cancel = true;

    this.WindowState = FormWindowState.Minimized
}

This code will give you the tray icon and re-show the form when double clicked.

    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;
    }
PeteGO
  • 5,597
  • 3
  • 39
  • 70