[Last Call] Learn how to a build a cloud-first strategyRegister Now


MessageBox Center Text?

Posted on 2006-06-08
Medium Priority
Last Modified: 2007-12-19
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???);            
Question by:kvnsdr
  • 2
LVL 25

Accepted Solution

dstanley9 earned 252 total points
ID: 16861251
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:


and Here's one that's already built:
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 248 total points
ID: 16861310
Hi dstanley9,

> Here's an examplt in VB.NET:

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

LVL 25

Expert Comment

ID: 16863004
Anything I can do to help :)

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question