Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# Tutorial
Next article icon

Label in C#

Last Updated : 20 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In Windows Forms, Label control is used to display text on the form. It does not interact with user input or handle mouse or keyboard events. Labels are used to provide information to the user within the form such as description, message, or details. These are the key points about labels.

  • Display Text or Image: It is mainly used to show the text or image in form.
  • Non-Interactive: It is non-interactive and just shows the text not like buttons and textbox.
  • Positioning: Labels can be placed anywhere on the form we can use drag and drop and also specify their coordinates using code.
  • Auto-Size: Labels can automatically adjust their size and fit according to the content when we set the AutoSize property as true.

Ways To Create Labels in Windows Forms

There are mainly two ways to create labels in the Windows Forms:

  • Design Time (Drag and drop)
  • Run Time (Custom code)

Design Time ( Drag and drop)

This is the easiest way to create labels in Windows Forms using Visual Studio we just have to open the toolbox and drag and drop the label on the form in the designer and further we can change the appearance of the label using the properties. Follow these steps to create a label.

Step 1: Now locate the project with the name here we are using the default name which is Form1 and it will open a form in the editor that we can further modify.

Empth-forms

In the image, we have two files that are open one Design and there is Form1.cs these two play a major role. We use the Form 1.cs file for the custom logic.


Step 2: Now open a Toolbox go to the view > Toolbox or ctrl + alt + x.

ToolBox


Step 3: Choose labels from the common controls in Toolbox as shown below:

LabelIntro


And then drag-and-drop in the form:

DragAndDrop


Step 4. Now open the properties of the label, press right-click on the label and go to properties it will open Solution Explorer now we can change the appearance and behaviour of the label in properties.

Properties


Now we can change the appearance and behaviour of the label such as background and text color or font size. These are the changes we made to the label

PropertiesAfterChange


Similarly, we can create different labels here is the output

Output:

Output


Run Time (Custom Code)

In this method, we are going to modify the Form1.cs file and add custom code modification in C# to change the appearance of the button according to our requirements. Follow these step-by-step processes.

Step 1: Create a label using the Label() constructor provided by the Label class.

// Creating label using Label class

Label mylab = new Label();


Step 2: After creating the Label, set the properties of the Label provided by the Label class.

// Set the text in Label

mylab.Text = “GeeksforGeeks”;


// Set the location of the Label

mylab.Location = new Point(222, 90);


// Set the AutoSize property of the Label control

mylab.AutoSize = true;


// Set the font of the content present in the Label Control

mylab.Font = new Font(“Calibri”, 18);


// Set the foreground color of the Label control

mylab.ForeColor = Color.Green;


// Set the padding in the Label control

mylab.Padding = new Padding(6);


Step 3: And last add this Label control to form using the Add() method.

// Add this label to the form

this.Controls.Add(mylab);


Step 4: Now double-click on the form in Design and it will open the Form.cs file where code is written in C#. Here the program file is Form 1.cs Now write this code in Form1.cs file

Form1.cs file:

C#
namespace WinFormsApp1 {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }          private void Form1_Load(object sender, EventArgs e)         {             // Creating and setting the label              Label mylab = new Label();             mylab.Text = "GeeksforGeeks";             mylab.Location = new Point(222, 90);             mylab.AutoSize = true;             mylab.Font = new Font("Calibri", 18);             mylab.ForeColor = Color.Green;             mylab.Padding = new Padding(6);              // Adding this control to the form              this.Controls.Add(mylab);         }     } } 

Output:

Output


Properties of Label Control

PropertyDescription
AutoSizeThis property is used to set a value indicating whether the Label control is automatically resized to display its entire contents.
BackColorThis property is used to set the background colour for the Label control.
BackgroundImageThis property is used to set the background image for the Label control.
BorderStyleThis property is used to set the border style for the Label control.
FlatStyleThis property is used to set the flat style appearance of the label control.
FontThis property is used to set the font of the text displayed by the Label control.
FontHeightThis property is used to set the height of the font of the Label control.
ForeColorThis property is used to set the foreground colour of the Label control.
HeightThis property is used to set the height of the Label control.
ImageThis property is used to set the image that is displayed on a Label.
LocationThis property is used to set the coordinates of the upper-left corner of the Label control relative to the upper-left corner of its form.
NameThis property is used to set the name of the Label control.
PaddingThis property is used to set padding within the Label control.
SizeThis property is used to set the height and width of the Label control.
TextThis property is used to set the text associated with this Label control.
TextAlignThis property is used to set the alignment of text in the label.
VisibleThis property is used to set a value indicating whether the control and all its child controls are displayed.
WidthThis property is used to set the width of the Label control.


Next Article
C# Tutorial
author
ankita_saini
Improve
Article Tags :
  • C#

Similar Reads

  • ref in C#
    The ref keyword in C# is used for passing or returning references of values to or from Methods. Basically, it means that any change made to a value that is passed by reference will reflect this change since you are modifying the value at the address and not just the value. It can be implemented in t
    4 min read
  • C# Variables
    In C#, variables are containers used to store data values during program execution. So basically, a Variable is a placeholder of the information which can be changed at runtime. And variables allows to Retrieve and Manipulate the stored information. In Brief Defination: When a user enters a new valu
    4 min read
  • while Loop in C#
    Looping in a programming language is a way to execute a statement or a set of statements multiple number of times depending on the result of the condition to be evaluated. while loop is an Entry Controlled Loop in C#. The test condition is given in the beginning of the loop and all statements are ex
    2 min read
  • C# Main Thread
    In C#, threads are the smallest units of execution that allow parallel execution of code, enabling multiple tasks to run concurrently within a single process. The Thread class in the System.Threading namespace is used to create and manage threads. In C#, the Main method is the entry point of any con
    5 min read
  • C# Tutorial
    C# (pronounced "C-sharp") is a modern, versatile, object-oriented programming language developed by Microsoft in 2000 that runs on the .NET Framework. Whether you're creating Windows applications, diving into Unity game development, or working on enterprise solutions, C# is one of the top choices fo
    4 min read
  • C# Literals
    In C#, a literal is a fixed value used in a program. These values are directly written into the code and can be used by variables. A literal can be an integer, floating-point number, string, character, boolean, or even null. Example: // Here 100 is a constant/literal.int x = 100; Types of Literals i
    5 min read
  • ulong keyword in C#
    Keywords are the words in a language that are used for some internal process or represent some predefined actions. ulong is a keyword that is used to declare a variable which can store an unsigned integer value from the range 0 to 18,446,744,073,709,551,615. It is an alias of System.UInt64. ulong ke
    2 min read
  • C# - if Statement
    In C#, if statement is used to indicate which statement will execute according to the value of the given boolean expression. When the value of the boolean expression is true, then the if statement will execute the given then statement, otherwise it will return the control to the next statement after
    3 min read
  • C# StringBuilder
    StringBuilder is a Dynamic Object. It doesn’t create a new object in the memory but dynamically expands the needed memory to accommodate the modified or new string.A String object is immutable, i.e. a String cannot be changed once created. To avoid string replacing, appending, removing or inserting
    4 min read
  • How to set Text on the Label in C#?
    In Windows Forms, Label control is used to display text on the form and it does not take part in user input or in mouse or keyboard events. You are allowed to set the text in the Label control using the Text Property. It makes your label more attractive. You can set this property using two different
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences