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:
What am I doing wrong?
Press Alt + F1 and that window will minimize to the tray.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With