Click here to Skip to main content
15,902,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys.

I have a problem with my application.

All MessageBox are shown in background behind the application. The form owner of messagebox is not TopMost. can anyone think of a solution why this is happening?

Thanks
Posted
Comments
Dylan Morley 14-Sep-11 11:32am    
Are you doing anything with threading?

Can you post the code that you are using to show the message box (the routine, not just the single line!)
Eli Nurman 14-Sep-11 13:12pm    
I am not threading at all
Using the following code:
MessageBox.Show(MainForm, Q, "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
Also
MessageBox.Show(null, Q, "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
does not seem to help

Message boxes appear on top of everything else within the same thread. Getting a message box behind some other controls indicates that the message box is created on a different thread to the form which can be moved over it.

If you're threading (including asynchronous I/O, sockets etc; background workers; thread pools; and .Net 4 Tasks), you should use BeginInvoke (or Invoke, if you want the thread method to stall while the message box is up) to call UI functionality like spawning message boxes.

BeginInvoke is on any Control in WinForms, or through the Dispatcher in WPF.
 
Share this answer
 
You may try overload which accepts IWin32Window (in case of System.Windows.Forms.MessageBox) or Window (in case of System.Windows.MessageBox).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900