O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Add Line Breaks to a Label Control

Problem

You want to insert line breaks in the text of a Web control such as the Label control.

Solution

Add HTML markup to the string. For example, you can use <p> to denote paragraphs or <br> to divide a line.

Discussion

You can’t use the carriage return character (or the System.Environment.Newline constant) to insert a line break in the text of a Web control. Instead, you must use HTML tags. For example, the following code snippet creates three lines of text:

lblMessage.Text = "This is line one.<br>"
lblMessage.Text &= "This is line two.<br>"
lblMessage.Text &= "This is line three."

Figure 15-4 shows the use of multiple lines in a Web control.

Figure 15-4. Multiple lines in a label.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required