how to put an .net application in system tray when minimized?

后端 未结 3 711
臣服心动
臣服心动 2021-02-03 12:12

can anyone please suggest a good code example of vb.net/c# code to put the application in system tray when minized.

3条回答
  •  Happy的楠姐
    2021-02-03 12:28

    Add a NotifyIcon control to your form, then use the following code:

        private void frm_main_Resize(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
               this.ShowInTaskbar = false;
               this.Hide();
               notifyIcon1.Visible = true;
            }
        }
    
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();
            this.WindowState = FormWindowState.Normal;
            this.ShowInTaskbar = true;
            notifyIcon1.Visible = false;
        }
    

    You may not need to set the ShowInTaskbar property.

提交回复
热议问题