This form has a NotifyIcon object. When the user clicks on the Close button, I want the form not to close but to become invisible. And then, if the user wants to see the form again, he can double click on the icon in the systray. If the user wants to close the form, he can right click on the icon and select “close”.
Can someone tell me how to make the close button not close the form but make it invisible?
(or if someone can think of a better way to achieve the same objective by all means)
First, you want to handle your Main form’s
.FormClosingevent (or by overriding the OnFormClosing method). Cancel that by settinge.Cancelto true.Then, you use a
NotifyIconto add an icon to the system tray.Finally, hide the form by calling
.Hide().This should get you started. You probably want to make
nia member variable, so that you can continue to hide/show the icon as you show/hide your form.