I am working on c# winforms application. I am actively working with 2 monitors namely primary and secondary. When I run the application, Message Box always pops up on the primary monitor irrespective on which monitor I run the application.
Here below shown are the 2 ways I tried but Message Box pops up on primary monitor:
1.
MessageBox.Show("Test Success", "Success", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1,
MessageBoxOptions.ServiceNotification);
2.
MessageBox.Show("Test Success", "Success", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
Is there any way I can display Message Box on the monitor I run the application dynamically?
as already stated in the comment: don't specify the MessageBoxOptions
. Simply call it like this:
MessageBox.Show("Test Success", "Success", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
and it will appear on the same monitor as your application, right in front of it.
I want to display the Message Box on top of any other apps I have opened.
Then you should force the Form that is calling the MessageBox
to the surface. Call this before showing the message box:
this.TopMost = true;
MessageBox.Show(...