如何动态创建标签 [英] How to create label dynamically

查看:78
本文介绍了如何动态创建标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我的问题:
我想动态创建标签.

例如:我想每10秒创建一个名称不同的标签.
意思是:
标签lblTest = new Label();

第一次lblTest.Text ="1用户名";
10秒后,我想创建另一个标签,并将文本分配为"2 hi hello".
10秒后,再次创建另一个标签,并将文本分配为"3用户名密码,为什么"
等等


如何创建标签以使其能够动态存储所有数据,但可以动态地将其存储在不同的标签中,以及如何每隔50秒检索一次所有标签?

意思是:在前50秒中将显示5个标签,在后50秒中将显示10个标签,依此类推.

如何实现呢?

请提出

在此先感谢您.

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.

推荐答案

您已标记了ASP.NET& Winforms在这里.
了解有关计时器控件/类的信息.它会帮助您满足您的需求! (不会问为什么会有这种奇怪的行为!)

ASP.NET计时器控件:计时器控件 [计时器类 [
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[^]


您好,
关于第一种解决方案,您也应该针对网络进行此操作
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);
   }



用于Windows



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();
     }



最好的问候
米特瓦里(M.Mitwalli)



Best Regards
M.Mitwalli


这篇关于如何动态创建标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆