如何使用\\\<br/>在TextBox [英] How To Use \n In a TextBox

查看:163
本文介绍了如何使用\\\<br/>在TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发展,我使用一个字符串( generatedCode ),其中包含一个程序某些 \\\
进入在我使用它( textBox1.Text = generatedCode ),但是当我运行程序文本框中新行,而不是打破了行我看到一个正方形。

I'm developing a program that I'm using a string(generatedCode) that contains some \n to enter a new-line at the textBox that I'm using it(textBox1.Text = generatedCode), but when I'm running the program, instead of breaking that line I'm seeing a square.

请记住,我的文本框的值设置为

Remember that I've set the Multiline value of the textBox to True.

推荐答案

替换\\\
与\r\\\
- 这是Windows控件如何表示换行符(但请注底部):

Replace \n with \r\n - that's how Windows controls represent newlines (but see note at bottom):

textBox1.Text = generatedCode.Replace("\n", "\r\n");

textBox1.Text = generatedCode.Replace("\n", Environment.NewLine);

请注意:由于在评论中讨论的,您的可能的要使用 Environment.NewLine 。目前还不清楚,但 - 它的不明确是什么行分隔Windows窗体控件应该使用时,他们不会在Windows上运行。如果他们使用的平台默认,或Windows一(因为它是一个Windows GUI控制的一个端口)?一个MSDN中的例子的确实的使用 Environment.NewLine ,但我已经看到在MSDN可怕的错误之前的例子现在,该文档只是没有按。'T状态,这也是应该的。

Note: As discussed in comments, you may want to use Environment.NewLine. It's unclear though - it's not well-defined what line separator Windows Forms controls should use when they're not running on Windows. Should they use the platform default, or the Windows one (as it's a port of a Windows GUI control)? One of the examples in MSDN does use Environment.NewLine, but I've seen horribly wrong examples in MSDN before now, and the documentation just doesn't state which is should be.

在一个理想的世界里,我们只希望有一个行分隔符 - 甚至在第二个最好的世界里,每一个情况会明确界定该行分隔符它期待...

In an ideal world, we'd just have one line separator - and even in a second best world, every situation would clearly define which line separator it was expecting...

这篇关于如何使用\\\<br/>在TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆