Minimize to system tray
-
Add a NotifyIcon to your form and assign it an icon. set visible = false if you do not want it to be there all the time. In the event handler where you want the app to minimize to the tray do something like:
private void btn_MinimiseToTray_Click(object sender, System.EventArgs e) { this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; this.notifyIcon1.Visible = true; }
and reverse it all when the icon is clicked or on a context menu etc.... -
Add a NotifyIcon to your form and assign it an icon. set visible = false if you do not want it to be there all the time. In the event handler where you want the app to minimize to the tray do something like:
private void btn_MinimiseToTray_Click(object sender, System.EventArgs e) { this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; this.notifyIcon1.Visible = true; }
and reverse it all when the icon is clicked or on a context menu etc....Thanks! I successfully send the app to system tray. But I am having some trouble trying to restore it from the tray. private void NotifyIcon_Clicked(object sender, System.EventArgs e) { //None of this help, the form just disappeared, never to come back. WindowState=FormWindowState.Normal; ShowInTaskbar=true; BringToFront(); Focus(); Visible=true; return; } I just need one more tip for this. norm
-
Thanks! I successfully send the app to system tray. But I am having some trouble trying to restore it from the tray. private void NotifyIcon_Clicked(object sender, System.EventArgs e) { //None of this help, the form just disappeared, never to come back. WindowState=FormWindowState.Normal; ShowInTaskbar=true; BringToFront(); Focus(); Visible=true; return; } I just need one more tip for this. norm
did you try Activate() ? Free your mind...
-
did you try Activate() ? Free your mind...
-
did you try Activate() ? Free your mind...
Hi Guillermo, I've got it working - well, the title bar didn't get repainted properly. Part/Chunk of it (Titlebar) appears dark. I called Invalidate(), which got rid of the problem in client area, not the title bar... private void NotifyIcon_Clicked(object sender, System.EventArgs e) { WindowState=FormWindowState.Normal; ShowInTaskbar=true; BringToFront(); Focus(); Visible=true; ClientSize = new System.Drawing.Size(292, 318); Location = formLocation; Invalidate(); return; } private void Form_Clicked(object sender, System.EventArgs e) { formLocation = this.Location; WindowState = FormWindowState.Minimized; ShowInTaskbar = false; notifyIcon.Visible = true; return; } norm
-
Hi Guillermo, I've got it working - well, the title bar didn't get repainted properly. Part/Chunk of it (Titlebar) appears dark. I called Invalidate(), which got rid of the problem in client area, not the title bar... private void NotifyIcon_Clicked(object sender, System.EventArgs e) { WindowState=FormWindowState.Normal; ShowInTaskbar=true; BringToFront(); Focus(); Visible=true; ClientSize = new System.Drawing.Size(292, 318); Location = formLocation; Invalidate(); return; } private void Form_Clicked(object sender, System.EventArgs e) { formLocation = this.Location; WindowState = FormWindowState.Minimized; ShowInTaskbar = false; notifyIcon.Visible = true; return; } norm
Good. When I did it, I used Form.Hide() instead of changing the windowstate, so I didn't have the problem of repainting. When I clicked on the taskbar icon, I used Form.Show(). In that way, it did good for me.. Free your mind...
-
Good. When I did it, I used Form.Hide() instead of changing the windowstate, so I didn't have the problem of repainting. When I clicked on the taskbar icon, I used Form.Show(). In that way, it did good for me.. Free your mind...
-
What i am doing is to generate a TrayIcon and use this code: // Public Bool for Closing the app bool boolAlowClose = false; // Press the closing Button at the app protected void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!boolAlowClose) { this.m_notifyicon.Visible = true; this.Hide(); e.Cancel = true; } else { e.Cancel = false; } } // ContextMenu from Trayicon to view the app again private void cmnu_View_Form_Click(object sender, System.EventArgs e) { this.m_notifyicon.Visible = false; this.Show(); } // This is the Menu "Close" hat close the application private void cmnu_Menu_Close_Click(object sender, System.EventArgs e) { boolAlowClose = true; this.Close(); } Hope this will help! Matthias
-
What i am doing is to generate a TrayIcon and use this code: // Public Bool for Closing the app bool boolAlowClose = false; // Press the closing Button at the app protected void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!boolAlowClose) { this.m_notifyicon.Visible = true; this.Hide(); e.Cancel = true; } else { e.Cancel = false; } } // ContextMenu from Trayicon to view the app again private void cmnu_View_Form_Click(object sender, System.EventArgs e) { this.m_notifyicon.Visible = false; this.Show(); } // This is the Menu "Close" hat close the application private void cmnu_Menu_Close_Click(object sender, System.EventArgs e) { boolAlowClose = true; this.Close(); } Hope this will help! Matthias