MessageBox Center Text?

Q. How do I center the text in a MessageBox?

MessageBox.Show("UserName and Password:" + "\n\n" + str_UserNamePass.ToString() + "\n\n" +
                            "Please keep in safe place!", Text.Center???);            
LVL 1
kvnsdrAsked:
Who is Participating?
 
dstanley9Connect With a Mentor Commented:
I don't htink you can do this with the standard messagbox - it's just a hook into the old WinAPI MessageBox, which doesn;t allow formatting AFAIK.

Two options come to mind:

Prepend your message with spaces to "center" the text - you may have to compute how many spaces to use for varialbe length lines.

Create your own messagebox, with a label, icon, and buttons.  That way you could center the label (or do any other formatting you want).  If you wanted to get really fancy, you could even support all of the same parameters as MessageBox.Show(), including dynamic buttons, icons, etc.

Here's an examplt in VB.NET:

http://www.levelextreme.net/wconnect/wc.dll?10,7,10,9

and Here's one that's already built:
http://ninopriore.com/modules.php?op=modload&name=News&file=article&sid=8&mode=thread&order=0&thold=0
0
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
Hi dstanley9,

> Here's an examplt in VB.NET:
http://www.levelextreme.net/wconnect/wc.dll?10,7,10,9

That's a very good article ;) Check the author name and the nickname for this comment for any similarity!

Cheers!
0
 
dstanley9Commented:
Anything I can do to help :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.