articles

Label Control in C#.Net

Label Control in C#.Net

Pushpendra Singh 17330 24-Jan-2011

Label control is used to display Text on the Form. Main property of the label control is the text property which is used to set the text in the label.

How to use Label Control

Drag and drop Label control from the toolbox on the window Form.

Label Control in C#.Net

Display Text in Label. 

         private void Form8_Load(object sender, EventArgs e)
        {
            // display text in Label
            label1.Text = "Hello";
        }

The text will display in Label when the Application run.

Label Control in C#.Net

Label Properties:

Text:   The text that appears on the Label control.

Enabled:  If this property is set to false, the Label appears grayed out.

 private void Form8_Load(object sender, EventArgs e)
        {
            //disable Label
            label1.Enabled = false;
        }

Label Control in C#.Net

BackColor:   Set the background color of Label control.

 private void Form8_Load(object sender, EventArgs e)
        {
            //change Label BackColor
            label1.BackColor = Color.CadetBlue;
        }

Output

Label Control in C#.Net

 ForeColor:  Set the ForeColor of Label control.

 private void Form8_Load(object sender, EventArgs e)
        {
            // change ForeColor of Label's text
            label1.ForeColor = Color.Red;
        }

Output

Label Control in C#.Net


c# c# 
Updated 03-Feb-2020

Leave Comment

Comments

Liked By