preserve line ending Windows Form Textbox
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?
You can try this:
XElement data = ...
myTextBox.Lines = data.Value.Split('\n');
精彩评论