Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting newline in .NET label

Tags:

I'd like to insert a newline into a Windows Forms text label through the design view. Something like setting the text to be:

Lorem ipsum \n dolor sit amet

or

Lorem ipsum <br/> dolor sit amet

However, none of the above works. How can one insert a new line into a label? I have a static text that I'll be displaying, so I don't want to do it via code.

like image 305
asenovm Avatar asked Dec 16 '12 10:12

asenovm


People also ask

How do I add a line break in label text?

Use Alt + Enter to insert a line break in Excel. Alternatively, you can enter label text directly into the chart labels on the slide. This gives you more control over line breaks and formatting.

How do I code a label in C#?

Step 1: Create a label using the Label() constructor is provided by the Label class. // Creating label using Label class Label mylab = new Label(); Step 2: After creating Label, set the properties of the Label provided by the Label class.


2 Answers

When you edit the "Text" field, you should see a small arrow on the right side of that text box. If you press it, a multiline string editor should appear. Here you can insert your mulitline text.

like image 186
user287107 Avatar answered Sep 27 '22 19:09

user287107


You can do it in the code as follows:

private void Form1_Load(object sender, EventArgs e) {      label1.Text = "This is the first line\r\nAnd this is the second line."; } 
like image 42
Water Cooler v2 Avatar answered Sep 27 '22 21:09

Water Cooler v2