How do I change the MessageBox location?

旧街凉风 提交于 2019-12-28 20:37:35

问题


I need to change the message box location. I don't want it to be in the center of the page.

MessageBox.Show("Hello");

回答1:


Normally, you can't change startup location of standard message box.

Solutions for your question:

  • Create your own custom message box. There is example of creation on CodeProject.
  • Complicated way using Windows Hook Procedure (WinAPI).



回答2:


You will need to create a new form that inherits from the MessageBox form. That is the only way to access the position properties.




回答3:


There is a way to change the location, but its way too complicated for such a small task.
If you really need to change its location, you could display it, then use GetForegroundWindow to get a window handle, then MoveWindow to your desired location.
But, as I already mensioned, this is way too complicated.
Just create your own form with a label on it an a "OK" button. Set the button as the default window button, and then, in Form1 do MyWndName.ShowDialog();




回答4:


What you can do is to create a new window, set the property AllowsTransparency to true and set the Background to Transparent. In that window you can put a TextBlock, or a label and also add Yes/No Buttons. Set the location of this window using Canvs.SetTop(Window,TopPosition) and Canvas.SetLeft(Window,LeftPosition). next, call the window with the method Show() or ShowDialog().



来源:https://stackoverflow.com/questions/5289148/how-do-i-change-the-messagebox-location

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