Mike Borozdin's Blog

A blog about programming, web and IT in general

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";


Tags:
Posted by Mike Borozdin on Saturday, June 14, 2008 12:59 PM GMT
  Shout it Kick it!  
Permalink | Comments (0) | Post RSSRSS comment feed
Comments are closed