Keep Messagebox.show() on top of other application using c#

I tried the solution provided by donutboy and it doesn't seem to accept 0x40000 (or 40000) as a valid option as a MessageBoxOptions Enum value.

However I have found that using MessageBoxOptions.DefaultDesktopOnly has the same effect and keeps the MessageBox on top until it is confirmed by the user. ie.

MessageBox.Show("Hello there", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);

This is likely the simplest native solution on offer.


There's a better solution, without creating a new form.

MessageBox.Show("Message Text", "Header", MessageBoxButtons.OK, MessageBoxIcon.None, 
     MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000);  // MB_TOPMOST

The 0x40000 is the "MB_TOPMOST"-Flag.


Another easy way to handle this:

MessageBox.Show(new Form { TopMost = true }, "This is TopMost", "TopMost", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);