How do I minimize a WinForms application to the no

2020-01-29 07:42发布

I want to minimize a C# WinForms app to system tray. I've tried this:

Having the application minimize to the system tray when button is clicked?. The first time I minimize it, it's nowhere to be found on the screen - taskbar/above taskbar/tray.

If i hit alt tab, I can see my app there; if I alt tab into it and minimize it again, it shows up above the taskbar:

minimize

What am I doing wrong?

4条回答
小情绪 Triste *
2楼-- · 2020-01-29 07:49

You need to add an icon on NotifyIcon for it to be visible.

查看更多
成全新的幸福
3楼-- · 2020-01-29 07:55

What about the option of hiding the form when minimized then showing once you click on the tray icon?

In the form resize event, do the check there and hide the form

   private void Form_Resize(object sender, EventArgs e)
    {
        if (WindowState == FormWindowState.Minimized)
        {
            this.Hide();
        }
    }

Then when clicking on the taskbar icon just restore it.

    private void notifyIcon_Click(object sender, EventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
    }
查看更多
Evening l夕情丶
4楼-- · 2020-01-29 08:12

You need to add a NotifyIcon to your form. You can then use the Click event of the NotifyIcon to have it set the Visible property on your Form to true again.

查看更多
时光不老,我们不散
5楼-- · 2020-01-29 08:13

You have to set the property ShowInTaskbar = true of your Form. It automatically minimizes to the task bar.

查看更多
登录 后发表回答