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:

Editing multiline label

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";
Share:
102,493
SilverLight
Author by

SilverLight

WEB DEVELOPER &amp; C# PROGRAMMER ASP.NET C# JQUERY JAVASCRIPT MICROSOFT AJAX MICROSOFT SQL SERVER VISUAL STUDIO

Updated on June 01, 2020

Comments

  • SilverLight
    SilverLight almost 4 years

    How can I add newlines to a Label's Text 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?

  • Candide
    Candide over 11 years
    Design time refers to the user designing the app in visual studio. All the code above is code-behind.
  • indiPy
    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
    Renae over 10 years
    @alliswell the design time option doesn't work, vs turns it into \\r\\n
  • Codezilla
    Codezilla almost 10 years
    All 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.
    Jakub S. over 7 years
    This is what i was looking for.
  • Rodri
    Rodri over 6 years
    Just 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
    monikapatelIT over 6 years
    doesn't work in my Visual Studio 2012 too. Thanks for the answer. I only know multiline mode exist only in textbox
  • Nikola Davidovic
    Nikola Davidovic over 6 years
    Hm, 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.