Label control in C#

In this article, we will learn how to use label in windows form in C#.

Let's create windows form.

Step 1
In Visual Studio select "File" = > "New" = > "Project..." then select C# Windows Forms Application then click Ok.

create windows form

Step 2
Let's create a label dialog then you go "View" = > select "ToolBox" (Crtl+Alt+X) = > then select "All Windows Forms" = > Choose "Label".

  1. First of all, we'll know about the "button".

    The label provides run-time information or descriptive text for a control. We'll discuss properties and function and events of label write down.

    "BackColor" changes the background color of label control.

    label1.BackColor = Color.AliceBlue;

    "BorderStyle" changes the style of label control border.

    label1.BorderStyle = BorderStyle.FixedSingle;

    "Click" when user mouse click on label control.

    label1.Click+=new EventHandler(label1_Click);
    private void label1_Click(object sender, EventArgs e)
      //code here

    "Cursor" when user mouse hover on label control then cursor style changed.

    label1.Cursor = Cursors.Hand;

    "Dispose()" released all resources used by the System.ComponentModel.Component.


    "DoubleClick" when user mouse double click on label control.

    label1.DoubleClick+=new EventHandler(label1_DoubleClick);
    private void label1_DoubleClick(object sender, EventArgs e)
      //code here

    "Enabled" changes the label control are enable or not.

    label1.Enabled = true;

    "FlatStyle" gets or sets flat style appearance of the label control.

    label1.FlatStyle = FlatStyle.Flat;

    "Focus()" focusing the label control.


    "Font" changes the style of the text of label control.

    label1.Font = new System.Drawing.Font("arial", 14.0F, FontStyle.Bold);

    "ForeColor" changes the font color of label control.

    label1.ForeColor = Color.AliceBlue;

    "Height" set the height of label control.


    "Hide()" hides the label control.


    "MouseClick" when user click the label by mouse.

    label1.MouseClick+=new MouseEventHandler(label1_MouseClick);
    private void label1_MouseClick(object sender, MouseEventArgs e)
        //code here

    "MouseDoubleClick" when user double click the by mouse.

    label1.MouseDoubleClick += new MouseEventHandler(label1_MouseDoubleClick);
    private void label1_MousuDoubleClick(object sender, KeyPressEventArgs e)
       //code here

    "MouseEnter" when mouse pointer enters the label control.

    label1.MouseEnter+=new EventHandler(label1_MouseEnter);
    private void label1_MouseEnter(object sender, EventArgs e)
       //code here

    "MouseHover" when mouse pointer rests/hover on the label control.

    label1.MouseHover+=new EventHandler(label1_MouseHover);
    private void label1_MouseHover(object sender, EventArgs e)
       //code here

    "MouseLeave" when mouse pointer leaves the label control.

    label1.MouseLeave+=new EventHandler(label1_MouseLeave);
    private void label1_MouseLeave(object sender, EventArgs e)
       //code here

    "MouseMove" when mouse pointer moves the label control.

    label1.MouseMove+=new MouseEventHandler(label1_MouseMove);
    private void label1_MouseMove(object sender, MouseEventArgs e)
       //code here

    "Padding" sets the padding on label control.

    label1.Padding = new Padding(10, 10, 10, 10);

    "ResetText()" resets all properties of label to its default values.


    "Show()" displays the label control.


    "Text" gets or sets text on label control.

    label1.Text = "Submit";

    "TextAlign" gets or sets text align on label control.

    label1.TextAlign = ContentAlignment.MiddleRight;

    "Visible" gets or sets the label control visible or not.

    label1.Visible = true;

Write a comment

Name Email Message