控件之间相互调用传值
请教个问题,在form1中动态创建了3000个label控件,name分别为lb[0]到lb[2999].现在创建timer控件来调用这些label控件,显示错误 “ 当前上下文中不存在名称“lb” ”。这个问题该怎么解决呢?能不能通过动态的设置这3000个label的modifiers属性来实现呢? c# modifiers --------------------编程问答-------------------- public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
Label [] lb = new Label[3000];
for(int i = 0; i < 3000; i++)
{
lb[i] = new Label();
lb[i].Location = new System.Drawing.Point( 80+12 * (i % 100),180+15 * (i / 100));
lb[i].Name = "btnTest";
lb[i].Size = new System.Drawing.Size(10, 12);
lb[i].Text = ".";
lb[i].BackColor = Color.White;
lb[i].Modifiers=public;
//lb[i].Font = new Font("微软雅黑", 30, FontStyle.Bold, GraphicsUnit.Pixel);
this.Controls.Add(lb[i]);
}
}
public void timer1_Tick(object sender, EventArgs e)
{
int Vmax;
Vmax = int.Parse(textBox2.Text);
int q=0;
int m;
int v=0;
int j;
for (j = 0; j < 100; j=j + v)
{
if (lb[j].Text != ".")
{
v = int.Parse(lb[j].Text);
for (m = 1; m <= v; m++)
{
if (lb[j + m].Text == ".")
{
q = 1;
}
else
{
q = 0;
break;
}
}
if (q == 1 && v < Vmax)
{
v++;
}
else if (q == 0 && v > 0)
{
v--;
}
else v = v + 1 - 1;
}
lb[j + v].Text = v.ToString();
lb[j].Text = ".";
}
在 void timer1_Tick里面调用lb[i]等 就显示上下文不存在“lb” 怎么解决呢?谢谢 --------------------编程问答-------------------- 应该把lb定义成全局变量吧
补充:.NET技术 , C#