I am trying to get a message box to pop up in front of all windows so the user will see it. I have the following code but it seems to put the message box to the very back.
DialogResult dlgResult = MessageBox.Show(new Form() { TopMost = true }, "Do you want to continue?", "Continue?",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dlgResult == DialogResult.Yes)
{
Console.WriteLine("YES");
}
else if (dlgResult == DialogResult.No)
{
Console.WriteLine("NO");
}
The above code is run in a thread is this my problem and how would I fix this?
Thanks
The best option, in a situation like this, is probably to use P/Invoke to call the MessageBox function directly. You can then include the
MB_TOPMOSTflag, which will force this to be a topmost message box. (This is not exposed in the managed API.)This would be declared as (from pinvoke.net):
Then called as: