问题
Is there any possibility to show a MessageBox
on the Primary Screen, not necessarily on the screen where the application is running?
回答1:
You could try MessageBoxOptions.DefaultDesktopOnly
:
MessageBox.Show("Hello World", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
Works pretty well for me, but doesn't render the message box with the default visual style of Windows.
回答2:
There is not an easy way to do it, but here is one way:
First create a Form or Window that is very small (1x1) or something. Make sure that this Form opens up on the primary display. You can get the primary display dimensions by using the Screen object. Make sure to set the properties of the form so it doesn't show up in the task bar.
Then call Messagebox.Show and pass in the Form.Handle to the show method. This tells the system to display the messagebox in front of that object. https://msdn.microsoft.com/en-us/library/cked7698(v=vs.110).aspx
Last, make sure to close the form you opened immediately after the Show call so that it doesn't create zombie forms.
来源:https://stackoverflow.com/questions/29700586/how-do-i-do-messagebox-show-on-primary-screen