Activate minimized form

G

Guest

I have a Windows form application that I generally run minimized. When a
critical event occurs it instantiates another "Alert" form which I want to
grab the user focus.

In the Alert constructor I call both this.Show() and this.Activate(), but if
the parent application is minimized then the Alert form will also stay
minimized (and just flash).

How can I cause the Alert form to show itself and grab focus?
 
T

TerryFei

Hi,
Welcome to MSDN Newsgroup!

There are strict rules around when an application can actually activate and
steal focus from whatever the user is currently doing. Besides interrupting
the user's workflow, it can cause serious problems if say a user is
currently typing in a password into a text box, stealing focus is not the
right thing to do.

See the remarks section of SetForegroundWindow
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui
/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setf
oregroundwindow.asp

The other behavior you are describing (parent application being
minimized/alert form staying minimized) sounds like somehow your alert form
is owned by the parent form? When a window is owned by another window it
will tend to stay in front of the owner window and minimize when the owner
window minimizes.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/
msdn_styles32.asp

You might consider a notify icon application instead with a toaster window
that pops up alerts when critical things happen.
http://www.windowsforms.net/articles/notifyiconapplications.aspx

Toaster window sample in here
http://www.windowsforms.net/Samples/download.aspx?PageId=1&ItemId=198&tabind
ex=4

I hope the above information is helpful for you. If you have any questions,
please feel free to let me know. Thanks and have a nice day!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top