By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

How to CRLF in MessageBox

P: 13
I would like to know how to put text over 2 (or several) lines in a messageBox

I tried MessageBox.Show("Text-1" + "\\r\\n" + "text-2"); but that doesn't work
Feb 20 '09 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 229
Why the double backslash?

"\r\n" should work, but a better way would be to use Environment.NewLine.
Feb 20 '09 #2

P: 10
When you say "\\r\\n" , it should print "\" instead of "\\". so they are treated as 4 characters not the two.

as said, Environment.NewLine is the best option to cope with this.
Feb 20 '09 #3

Curtis Rutland
Expert 2.5K+
P: 3,256
Yes, the problem is your double backslashes.

A single backslash and the following character is an escape sequence. So when you do "\\r" what you are literally doing is escaping the second backslash, so the literal string result is: "\r" What you should be doing is "\r" which is interpreted as a carriage return.

However, I also agree with everyone else. Environment.NewLine is a handy way to avoid escape sequences.
Feb 20 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.