How to center text in a MessageBox in .NET? (say C# or VB.NET?) Also, pad left, or pad right.
Migrating to .NET:)
-
-
It's not possible with the .NET methods. You need to do a P/Invoke (call native methods) to be able to achieve that. Or you create your own MessageBox class (but that means you need to implement everything on your own!).
The .NET MessageBox follows the standard messagebox that is provided by Windows, without any custom features.
I, personally, don't like customized messageboxes because standard elements should look standard in each application. But this is a personal opinion. -
http://msdn.microsoft.com/msdnmag/issues/02/11/CuttingEdge/
This MSDN Magazine article describes how to use P/Invoke and Windows hooks to extend the functionality of MessageBox in .NET. -
I forgot to post some links yesterday

http://www.codeproject.com/cs/miscctrl/CsMsgBoxTimeOut.asp (Messagebox with timeout)
http://www.codeproject.com/cs/miscctrl/MessageBoxIndirectCS.asp (Advanced Messagebox implementation)
http://www.codeproject.com/cs/miscctrl/MessageBoxChk.asp (Checkbox in messagebox)
All samples are done in C# -
NOOOOOOO. Do NOT reinvent the wheel. Google is your friend. It is always bad practice to roll your own messagebox.littleguru wrote:It's not possible with the .NET methods. You need to do a P/Invoke (call native methods) to be able to achieve that. Or you create your own MessageBox class (but that means you need to implement everything on your own!).
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.