How do I minimize a WinForms application to the notification area?

狂风中的少年 提交于 2019-11-27 14:18:10

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;
    }

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!