Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi all
 
My problem:
I want to create a label dynamically.
 
Example:In every 10 second i want to create a label with different name.
means:
Label lblTest = new Label();
 
for 1st time lblTest.Text = "1 username";
after 10 second i want to create another label and assign the text as "2 hi hello"
after 10 second again create another label and assign the text as "3 username password why"
and so on
 

How to create a label so that it will store all the data but in different labels dynamically and how to retrieve all the labels after each 50 second?
 
Means :In first 50 second it will show 5 label ,after next 50 second it will show 10 labels and so on.
 
How to achieve this?
 
Please suggest
 
Thanks in advance.
Posted 18-Apr-12 5:23am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You have tagged both ASP.NET & Winforms here.
Read about Timer control/Class. It would help you in what you need! (Would not ask why such a odd behaviour!)
 
ASP.NET Timer control: Timer control[^]
Winforms: Timer Class[^]
  Permalink  
Comments
Nelek at 18-Apr-12 16:54pm
   
I think you failed in voting, there is no votes of 5 so far
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi ,
Regarding to the First solution you should do that also for web
int countTimes = 0;
   protected void Timer1_Tick(object sender, EventArgs e)
   {
       if (ViewState["countTimes"] == null)
       {
           countTimes = 1;
       }
       else
       {
           countTimes = Convert.ToInt32(ViewState["countTimes"]);
       }
       for (int i = 0; i < countTimes; i++)
       {
           Label lbl = new Label();
           txtSkill.ID = "lbl" + i;
           Form.Controls.Add(lbl);
       }
       countTimes = countTimes + 1;
       ViewState.Add("countTimes", countTimes);
   }
 
for windows
int i = 1;
     private void timer1_Tick(object sender, EventArgs e)
     {
         Button button1 = new Button();
 
         button1.Location = new System.Drawing.Point(105 + 20 * i, 92 + 20 * i);
         button1.Name = "button" + i;
         button1.Size = new System.Drawing.Size(75, 23);
         button1.TabIndex = 0 + i;
         button1.Text = "button" + i;
         button1.UseVisualStyleBackColor = true;
         this.Controls.Add(button1);
         i++;
     }
 
     private void Form1_Load(object sender, EventArgs e)
     {
         timer1.Start();
     }
 
Best Regards
M.Mitwalli
  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 280
1 Sergey Alexandrovich Kryukov 279
2 CPallini 205
3 Maciej Los 197
4 Afzaal Ahmad Zeeshan 160
0 OriginalGriff 5,635
1 DamithSL 4,496
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 19 Apr 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