How do I do MessageBox.Show on primary screen?

自闭症网瘾萝莉.ら 提交于 2019-12-02 00:42:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!