You can do it easily in windows forms application. Following code snippet only generates a label
at specific location with hardcoded text and some basic properties settings. You can modify it according to your requirement e.g. you can change label name, location, text
accordingly. Hope this will be helpful for you.
private void button1_Click(object sender, EventArgs e)
{
var lblnew = new Label
{
Location = new Point(50, 50),
Text = "My Label", //Text can be dynamically assigned e.g From some text box
AutoSize = true,
BackColor = Color.LightGray,
Font = new Font("Microsoft JhengHei UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, (byte)0)
};
//this refers to current form you can use your container according to requirement
Controls.Add(lblnew);
}
Or you can also use simplified initialization as follows;
private void button1_Click(object sender, EventArgs e)
{
var lblnew = new Label
{
Location = new Point(50, 50),
Text = "My Label", //Text can be dynamically assigned e.g From some text box
AutoSize = true,
BackColor = Color.LightGray,
Font = new Font("Microsoft JhengHei UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, (byte)0)
};
//this refers to current form you can use your container according to requirement
Controls.Add(lblnew);
}