Mike Borozdin's Blog

A blog about programming, web and IT in general

Search

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© 2012 Mike Borozdin

Difference Between Label.Text And TextBox.Text (WinForms) In Treating Line Breaks

I had a small project recently that outputted the results of some calculations to the label on the form, I replaced the label with a textbox and noticed that instead of the line breaks I had in the label I got a bunch of non-printed characters. I had the following code that worked fine for the label:

myLabel.Text += "\nNew Line";


However as I said it didn’t work properly for the textbox, however this one did work:

myTextBox.Text += "\r\nNew line";


This is good and it also works with the Label control, however you can do it better by using Environment.NewLine which represents the new line string on the current system:

myTextBox.Text += Environment.NewLine + "New line";

Kick it! Shout it

Tags:
Posted on Saturday, June 14, 2008
Comments (0)
blog comments powered by Disqus