FormWindowState

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
why does Me.WindowState = FormWindowState.Normal sometime bring a minimized window to normal behind another app instead of bringing it to the front?
 
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:

Flash a program icon in the task bar (VB.NET)
 
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.
 
Then if i want the app to come to the front, should i use Me.Topmost , Me.Activate or use SetForegroundWindow?

I already provided an answer in my previous post.
 
Back
Top