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.

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


Tags: ,
Posted by Mike Borozdin on Saturday, June 14, 2008 7:59 PM GMT
Bookmark on MSDN   Add to Technorati Favorites  Kick it!  
Permalink | Comments (0) | Post RSSRSS comment feed

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
Loading