Friday, March 4, 2011

Best practices for formatting a message for MessageBox.Show(...) in Winforms for Vista

In XP/2003 I had become accustomed to writing my MessageBox.Show(..) code like this :

MessageBox.Show("Title", "Sorry an error has occured!\n" +
                         "You may want to try one of the following:\n\n" +
                         "1. Reboot your machine\n" +  
                         "2. Buy a new machine\n" +  
                         "3. Report your error on StackOverflow.com.\n");

i.e. I formatted the message nicely and readable. If I didnt then it would fill the whole width of the screen and was not very friendly.

Now when the same message box comes up in Vista it is formatted completely differently and it introduces its own linefeeds and generally looks a lot worse.

What is the best practice for this for an application for both Vista and XP - short of writing my own message box class.

What are others doing to overcome this problem

From stackoverflow
  • Just a remark, but in Vista, is not a TaskDialog more appropriate for this kind of dialog ?

    alt text

    Otherwise, this thread does mention a way to insert newlines in a Messagebox.

    MessageBox.Show( "This" & Environment.NewLine & "is" & Environment.NewLine & "a test",
                     "Lines", MessageBoxButtons.YesNoCancel)
    

    See Environment.Newline property

0 comments:

Post a Comment