C# 消息框中的文本应该是下一行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11156159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Text in the message box should be the next next lines
提问by David Bekham
Basically i display the some text in the MessageBoxwith Okand Cancelbutton in WindowPhone 7.1.
基本上我在 WindowPhone 7.1的MessageBoxwithOk和Cancelbutton 中显示一些文本。
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?
实际上,我们可以简单地在 MessageBox 中添加文本,但是如何在 MessageBox 中的文本之间添加换行符.. 有没有办法在 Windows Phone 中做到这一点?
采纳答案by Charleh
You can use Environment.Newline for line breaks
您可以使用 Environment.Newline 换行
string msg = "Text here" + Environment.NewLine + "some other text";
回答by SHAKIR SHABBIR
You can try
你可以试试
\n or <br />for line Breaks. I am not sure if this will work:
\n 或<br />换行符。我不确定这是否有效:
Example:
例子:
string msg = "Some text will be here\nProperty:value";
MessageBox.Show(msg);
回答by hriziya
MessageBox.Show("aa" + Environment.NewLine + Environment.NewLine + "bb");
回答by KF2
MessageBox.Show("Line 1" + Environment.NewLine + "Line 2");
回答by newman
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+Enterto enter new line. All others will just show as raw text like "\n" or, "\r\n" or "<br />".
这是一篇旧帖子,但是...如果您的文本来自资源文件,则建议的解决方案均无效。在 VS 资源编辑器中,你必须使用Shift+Enter来输入新行。所有其他人将只显示为原始文本,如“\n”或“\r\n”或“<br />”。
回答by Raz Luvaton
There are 2 options \nand Environment.NewLine
有2个选项\n和Environment.NewLine
Option 1: \n
选项1: \n
I don't know if this work for sure on Windows phone but I think it would
我不知道这是否在 Windows 手机上确实有效,但我认为它会
\n- New line. Place as much as sentences as you want
\n- 新队。根据需要放置尽可能多的句子
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
选项 2: Environment.NewLine
Environment.NewLine- New line. Place as much as sentences as you want
Environment.NewLine- 新队。根据需要放置尽可能多的句子
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.
NewLine (Environment.NewLine) 提供的功能通常是术语换行、换行、换行、回车、CRLF 和行尾的含义。
I prefer \n because is shorter and faster but whatever you like.
我更喜欢 \n 因为它更短更快,但无论你喜欢什么。
回答by qjnr
If you have a veryverylarge message to display, use:
如果你有一个非常非常大的消息显示,使用:
MessageBox.Show(String.Join(Environment.NewLine,
"Line 1",
"Line 2",
"Line 3"));

