Last Updated : 30 Jun, 2019
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 location of the Label control using the
Location Propertyin the windows form. This property contains the coordinates of the upper-left corner of the Label control relative to the upper-left corner of its form. You can set this property using two different methods:
1. Design-Time:It is the easiest method to set the Location property of the Label control using the following steps:
2. Run-Time:It is a little bit trickier than the above method. In this method, you can set the location of the Label control in the windows forms programmatically with the help of given syntax:
public System.Drawing.Point Location { get; set; }
Here, the Point indicates the upper-left corner of the Label control relative to the upper-left corner of its form. Following steps are used to set the Location property of the Label:
// Creating label using Label class Label mylab = new Label();
// Set Location property of the label mylab.Location = new Point(222, 90);
// Add this label to the form this.Controls.Add(mylab);Example: CSharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp16 {
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;
// Adding this control to the form
this.Controls.Add(mylab);
}
}
}
Output:RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4