问题
Basically i display the some text in the MessageBox
with Ok
and Cancel
button in WindowPhone 7.1.
I need the requirement like the below.
Some text will be here....
Property:value...
Actually we can simply the text in the MessageBox, but how can i add the linebreak between the text in the MessageBox.. Is there any way to do this in Windows Phone?
回答1:
You can use Environment.Newline for line breaks
string msg = "Text here" + Environment.NewLine + "some other text";
回答2:
MessageBox.Show("Line 1" + Environment.NewLine + "Line 2");
回答3:
You can try
\n or <br />
for line Breaks. I am not sure if this will work:
Example:
string msg = "Some text will be here\nProperty:value";
MessageBox.Show(msg);
回答4:
MessageBox.Show("aa" + Environment.NewLine + Environment.NewLine + "bb");
回答5:
There are 2 options \n
and Environment.NewLine
Option 1: \n
I don't know if this work for sure on Windows phone but I think it would
\n
- New line. Place as much as sentences as you want
MessageBox.Show("Some Text Here In The Line NO.1\nSome Text Here In Line NO.2");
Will show:
Some Text Here In The Line NO.1
Some Text Here In Line NO.2
OR
MessageBox.Show("Some Text Here In The Line NO.1 +"\n" + "Some Text Here In Line NO.2");
Will show the same as the first one:
Some Text Here In The Line NO.1
Some Text Here In Line NO.2
Option 2: Environment.NewLine
Environment.NewLine
- New line. Place as much as sentences as you want
MessageBox.Show("Some Text Here In The Line NO.1" + Environment.NewLine + "Some Text Here In Line NO.2");
Will show the same as the first one:
Some Text Here In The Line NO.1
Some Text Here In Line NO.2
From msdn.microsoft
The functionality provided by NewLine (Environment.NewLine) is often what is meant by the terms newline, line feed, line break, carriage return, CRLF, and end of the line.
I prefer \n because is shorter and faster but whatever you like.
回答6:
This is a old post, but... If your text comes from resource file, none of the suggested solution works. In VS resource editor, you have to use Shift+Enter to enter new line. All others will just show as raw text like "\n" or, "\r\n" or "<br />".
回答7:
If you have a very very large message to display, use:
MessageBox.Show(String.Join(Environment.NewLine,
"Line 1",
"Line 2",
"Line 3"));
来源:https://stackoverflow.com/questions/11156159/text-in-the-message-box-should-be-the-next-next-lines