保留 Windows 窗体文本框的行结尾
我在使用 Windows 窗体 textbox
控件时遇到了一些问题,我使用 XElement
对象的值填充内容。它的起源处的 xml
是以 Windows 行结尾编写的,因此我希望当我在 textbox
中呈现此内容时,它的格式会正确,但事实并非如此。 t。每一行结尾都缺失,内容以一大行呈现。 我之前将控件设置为多行,但显然这只允许显示多于一行,但它与它如何解释我传递给它的文本无关。
解决这个问题的正确方法是什么?
更新
我发现这不是文本框的问题,而是我访问数据的方式的问题。如果我使用 XElement,我只会得到一大行,如果我使用 XmlElement,我会得到格式良好的代码。代码如下:
XDocument doc = XDocument.Load("XMLFile1.xml");
textBox1.Text = doc.Descendants("dos").Single().Value;
XmlDocument doc2 = new XmlDocument();
doc2.Load("XMLFile1.xml");
textBox2.Text = doc2.GetElementsByTagName("dos")[0].InnerText;
然后问题将以这种方式重新表述:如何使用保留换行符的 XElement 恢复文本?
I have a little problem using the windows forms textbox
control, I populate the content using the value of an XElement
object. The xml
from where it origins is writing with windows line ending so I was having the hope that when I present this content in the textbox
it will be correctly formated but it doesn't. Every line ending is missing and the content is presented in one big line.
I set the control to multiline
previously but apparently this only permits to show more than one line but it has nothing to do with how it interprets the text that I pass to it.
What is the correct way to fix this problem?
UPDATE
I found that is not a problem of the textbox is a problem of how i'm accesing the data. If i use an XElement i get only one big line and if i use an XmlElement i get the code well formatted. Here is the code:
XDocument doc = XDocument.Load("XMLFile1.xml");
textBox1.Text = doc.Descendants("dos").Single().Value;
XmlDocument doc2 = new XmlDocument();
doc2.Load("XMLFile1.xml");
textBox2.Text = doc2.GetElementsByTagName("dos")[0].InnerText;
Then the question will be reformulated this way: How can i recover the text using an XElement preserving the line feeds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以试试这个:
You can try this: