blah blah blah is here! blah blah » Close

up0down
link

I've done quite a bit of searching on this and found no real answer.
Is this just a limitation of MessageBoxes?

Just to clarify - I have my main process running as BackgroundWorker and when it is finished, a message box appears to report all finished. Unfortunately it will not be the uppermost window and is often hidden completely behind the program window.

Is there a simple solution to this or do I have to live with it?

Thanks as always in advance.

last answered one year ago

1 answers

link

It sounds like your program's form has its Topmost property set to true (the default is false).

If that's the case, then try setting Topmost to false just before calling MessageBox.Show and set it back to true immediately afterwards.

EDIT

OK, in that case, see if the following pattern will work:

this.SendToBack();
MessageBox.Show("Hopefully on top now!");
this.BringToFront();


SECOND EDIT

Some of the overloads of MessageBox.Show take an IWin32Window object (basically just a window) as the first parameter. This makes the window the MessageBox's owner and, in theory, a window should always appear on top of its owner.

So I'd try something like the following:
MessageBox.Show(this, "Hopefully on top now!");

If there is still another window on top of the MessageBox, then set your form's Topmost property to true first.

MickW
151

Thanks for the feedback. I did check that and the property is set to false.

vulpes
17279

Please see my edit.

MickW
151

Damn. That didn't work either. I'm using a save.dialog just before this step - could that be anything to do with it?

vulpes
17279

I wouldn't have thought that would make any difference. However, I've had another idea - please see my second edit.

MickW
151

Sweet! Second edit cracked it. Many thanks!

Feedback