Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows Application
How to Create dynamic lable in windows application using c#
Posted 16-Mar-12 20:43pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

 public partial class newTemplate : Form
    {
        int i = 0;
        int x = 22;
        int noofcontrols = 0;
        TextBox[] t1 = new TextBox[25];
        Label[] l1 = new Label[25];
        public newTemplate()
        {
            InitializeComponent();
        }
.
.
.
}
 
 
here i am creating labels on button click, you can do as your requirement
 private void button2_Click(object sender, EventArgs e)
        {
          
            t1[i] = new TextBox();
            l1[i] = new Label();
            t1[i].Size = new System.Drawing.Size(244, 22);
            t1[i].Location = new System.Drawing.Point(85, x);
            l1[i].Location = new System.Drawing.Point(60, x);
            l1[i].Font =new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            l1[i].Text = i.ToString()+". ";
                
            // t[i].Name = drform[0].ToString();
            t1[i].TabIndex = i;
            t1[i].Name = "txt"+i;
           
            panel1.Controls.Add(t1[i]);
            panel1.Controls.Add(l1[i]);
            panel1.AutoSize = true;
            panel1.Show();
            panel1.Refresh();
            t1[i].Focus();
            i++;
            x = x +30 ;
            noofcontrols++;
            
 
        }
 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try
public void AddMyControls()
 {
    TextBox textBox1 = new TextBox();
    Label label1 = new Label();
 
    // Initialize the controls and their bounds.
    label1.Text = "Text    label1.Location = new Point(48,48);
    label1.Size = new Size (104, 16);
 
    // Add the Label control to the form's control collection.
    Controls.Add(label1);
 }
 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Label lbl = new Label();
lbl.Text = "lable add";
lbl.AutoSize = true;
lbl.ForeColor = Color.Red;
lbl.Location = new Point(850, 335); //set ur desire loction here
this.Controls.Add(lbl);
lbl.BringToFront();
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 DamithSL 165
4 Tomas Takac 144
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 17 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100