Add NewLine to label's Text at design time
102,493
Solution 1
When you click on the label Text property in the Property window for the label, a drop down will appear in which you can, when you press Enter, go to the new line. I just tried it, and it works in Visual Studio 2010.
Here's a screenshot to clarify:
Solution 2
Design Time \r\n will do the trick -
label1.Text = "Multi-line \r\nlabel"
Also you can try setting in designer generated code -
this.label2.Location = new System.Drawing.Point(151, 120);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Multi-line \r\n label";
Run time -
label1.Text = "Multi-line" + Environment.NewLine + "label";
Solution 3
You can use <br />
in your string, for example :
MyLabel.Text = "This is my text" + "<br />" + "This is my new line text";
Author by
SilverLight
WEB DEVELOPER & C# PROGRAMMER ASP.NET C# JQUERY JAVASCRIPT MICROSOFT AJAX MICROSOFT SQL SERVER VISUAL STUDIO
Updated on June 01, 2020Comments
-
SilverLight almost 4 years
How can I add newlines to a
Label
'sText
at design time? There are some posts on Stack Overflow on how to do this in code-behind, but there is no post about that for design time yet, it seems?-
Peter Mortensen over 7 yearsPossible duplicate of Word wrap for a label in Windows Forms
-
-
Candide over 11 yearsDesign time refers to the user designing the app in visual studio. All the code above is code-behind.
-
indiPy over 11 years@Candide what makes you say that? I clearly mentioned that this is designer generated code and if you think designer generated code is not design time then I will happily delete my answer.
-
Renae over 10 years@alliswell the design time option doesn't work, vs turns it into \\r\\n
-
Codezilla almost 10 yearsAll this time I've been using textboxes for the multiline because I never could figure that out in the properties window lol.. Thanks man.
-
Jakub S. over 7 yearsThis is what i was looking for.
-
Rodri over 6 yearsJust a comment, it does not work in legacy versions of Visual Studio, like Visual Studio NET 2003 (Net Framework 1.1). Of course, they barely exist but take it into account if you are doing something in a legacy project ;)
-
monikapatelIT over 6 yearsdoesn't work in my Visual Studio 2012 too. Thanks for the answer. I only know multiline mode exist only in textbox
-
Nikola Davidovic over 6 yearsHm, it should be working on VS2012. I think that my original answer was made after trying it in VS2012. Look at the time when I answered the question.