C# Label Control

Labels are one of the most frequently used C# control. We can use the Label control to display text in a set location on the page. Label controls can also be used to add descriptive text to a Form to provide the user with helpful information. The Label class is defined in the System.Windows.Forms namespace.

C# label

Add a Label control to the form - Click Label in the Toolbox and drag it over the forms Designer and drop it in the desired location.

If you want to change the display text of the Label, you have to set a new text to the Text property of Label.

label1.Text = "This is my first Label";

In addition to displaying text, the Label control can also display an image using the Image property, or a combination of the ImageIndex and ImageList properties.

label1.Image = Image.FromFile("C:\\testimage.jpg");

The following C# source code shows how to set some properties of the Label through coding.

Full Source C#
using System; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { label1.Text = "This is my first Lable"; label1.BorderStyle = BorderStyle.FixedSingle; label1.TextAlign = ContentAlignment.MiddleCenter; } } }