I'm trying to make my application minimize to system tray when I close the form.
I want it to minimize to tray when the Close button (red 'X') is clicked and preferably when the window is right clicked and 'Close' selected on the task bar.
However I want other forms of closing to remain intact. I.E. 'Alt-F4' and coded 'Form.Close()'
I tried looking for a solution and found that there is a 'FormClosingEvent.CloseReason' which contains 'CloseReason.UserClosing'
This is flagged when I click the Close button, but unfortunately it is also flagged when I use 'Alt-F4' and seemingly when the code uses 'Form.Close()'
I found several ways of intercepting 'Alt-F4', these are of no use to me, I wish 'Alt-F4' remain intact.
To clarify I wish to intercept ONLY: 'Close' button (red 'X') being clicked and the right-click close on the task bar.
Think of it like this:
1. The user clicks the red 'x'
2. The red 'x' calls a method/event
3. The method/event calls Form.Close()
I want to intercept before it reaches Form.Close(), preferably before 2 happens. Is there any way to do this?
I don't know all of the ways of closing the form and or application. Of those I know:
- Task Manager: Intact.
- Alt-F4: Intact.
- Shut Down: Intact.
- Red 'X' Close Button: Intercepted.
- Right-click task bar select 'Close': Intercepted.
I hope that helps.
Thank you for any help you can give.
Zynthia Zenithene