The WindowState is unrelated to the focus. Restoring your window doesn't say anything about whether it's focused or not. If you want to force your form to have focus then you need to call its Activate method.
It may be rather annoying for the user if they are working in another application and your window takes focus though. That's why Microsoft introduced the ability to make an application's Taskbar icon flash. It's a way of getting the user's attention on your app without stealing focus. That way they can finish wht they are doing in the other before switching. It also ensures that they don't keep typing and send keystrokes to your app that were meant for another. I have more than once performed actions in an application that stole focus because I was typing in another app at the time.
There's no managed method for flashing the Taskbar icon, but here's a VB.NET example of the unmanaged code required:
Then if i want the app to come to the front, should i use Me.Topmost , Me.Activate or use SetForegroundWindow? I have the app minimized to the tray. When i click the tray icon, i want the app to come up and to the front.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.