Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 680
Buffalo Avatar asked Jun 11 '11 16:06

Buffalo


People also ask

How do I minimize a program to the system tray?

Press Alt + F1 and that window will minimize to the tray.

How minimize windows form to System Tray in C#?

This can be done by doing the following in your form's Resize event handler: Check whether the form's WindowState property is set to FormWindowState. Minimized. If yes, hide your form, enable the NotifyIcon object, and show the balloon tip that shows some information. Once the WindowState becomes FormWindowState.

How do I turn off WinForms full screen?

The only thing you can do is completely disable resizing your window. In WinForms, you do that by setting the FormBorderStyle property to one of the following: FormBorderStyle. FixedSingle , FormBorderStyle. Fixed3D , or FormBorderStyle.

How do I fix WinForm size?

Right click on your form and go to properties. Then go to Layout options,see there are a property named Size. Change it as your need as width and length wise.


3 Answers

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;     } 
like image 146
Mohgeroth Avatar answered Oct 06 '22 01:10

Mohgeroth


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.

like image 23
Patrick Avatar answered Oct 06 '22 00:10

Patrick


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

like image 20
Fiur Avatar answered Oct 06 '22 01:10

Fiur