How do I make a MessageBox.Show on the main screen?

Is it possible to show MessageBox

on the main screen, not necessarily on the screen on which the application is running?

+3


source to share


2 answers


You can try MessageBoxOptions.DefaultDesktopOnly

:

MessageBox.Show("Hello World", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);

      



Works well for me, but doesn't display a message box with the default windows visual style.

+5


source


There is no easy way to do this, but this is one way:

First create a shape or window that is very small (1x1) or whatever. Make sure this form opens in the main display. You can get the primary dimensions of the display using the Screen object . Remember to set the properties of the form so that it does not appear in the taskbar.



Then call Messagebox.Show and pass the show method to Form.Handle. This tells the system to display a message box in front of this object. https://msdn.microsoft.com/en-us/library/cked7698(v=vs.110).aspx

Finally, remember to close the form you opened immediately after calling Show so that it doesn't create zombie shapes.

+1


source







All Articles