Share via


Centering a MessageBox

Message boxes are centered on the desktop. Occasionally I get a request for C# code for centering a message box to its owner. Before pointing you to some sample code, I would strongly encourage you to reconsider changing the default behavior of the system message box in your application because, by design, the message box is supposed to be a "please read me now" kind of thing. Additionally, the technique uses the SetWindowsHookEx function which has an application-wide impact and is thread-sensitive.

OK! If you still want to center the system message box to its owner, you can check out the sample code and read the technique at https://www.codeproject.com/cs/miscctrl/CenterDialog.asp.

Enjoy. -Tan