I am writting a program in vb.net that uses the systray and what I am trying to achieve is the following.
If the systray icon is clicked it should minimise/restore the form. (this I can do)
the bit I am stuck on is that if the form is ‘open’ and not focused I want it to get focus rather than minimise.
I can’t seem to find anything that does the test I need to see if the form is not in a minimised state and does not have focus.
Any suggestions welcome.
Thanks
Keep track of the form activation state by listening to the Activate and Deactivate events. One complication is that the form will be de-activated when you click the icon. Solve that by recording the time it happened. Like this:
This is otherwise a fairly unpleasant hack around having to set the form’s ShowInTaskbar property to False. It is possible to have a taskbar button and still keep the form invisible at startup. Check this answer for the approach.