Using the \n for a line break....

Basically, I read a part of a file, which is the description, which goes into a label, the 'description ' can be changed in the file, accordingy to what you want it to be. So, pretty much I need a way to insert line breaks between every few characters. And for some reason, \n in a file, thats read and put directly into a label, is different than adding "\n" in the compiler, onto the label......

Answer this question

Using the \n for a line break....

  • PrashG

    You've got several options, I can't say which one will work best for you:
    • Set the label's AutoSize property to False, it will automatically word-wrap the contents
    • Set the Text property with StreamReader.ReadToEnd(). That will reproduce the line breaks in the file in the label text
    • Use a multiline TextBox control with scrollbars.



  • Stark77

    Click on the Show All Files icon in the Solution Explorer. Open the node next to the form and double-click the Designer.cs file. Locate the InitializeComponent() function, expand the collapsed outline node if necessary. You should see the statement that generates the label Text property value. It will look something like this:

    this.label1.Text = "nobugz\\nwaz here";

    Delete the extra backslash and you're in business...


  • TomGoossens

    not entirely sure what you mean. Do you mean placing a linebreak in a label if so try \r\n or Environment.NewLine

  • Ketan1985

    Sorry if I didn't explain it clearly enough, but I have a label on my form, and its value is taken directly from a file, but what if the line in the .txt file, is really long, and the label will run off the form, and if I insert \n into the file, it just sees it as a word, not an escape sequence. How could I make it so the user can put line breaks in the file, that my program will see, and insert in the label, seeing as \n won't work in the file. Or somehow, make it so it will insert "\n" every 57 characters in the string that it gets from the file.
  • Kamii47

    when reading the line, replace \n with \r\n or replace it with Environment.NewLine (which is pretty much the same thing) then put it in the label.

  • Using the \n for a line break....