求助:我的Timer好象启动不了
public partial class Form1 : Form{
int flag = 1;
Label lab1 ;
char[] randchar;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
randchar = new char[52];
for (int i = 0; i < 26; i++)
{
randchar[i] = (char)('a' + i);
}
for (int i = 26; i < 52; i++)
{
randchar[i] = (char)('A' + i - 26);
}
}
#region 随机生成label
private void createLab()
{
lab1 = new Label();
Random rand = new Random();
int randNum= rand.Next(52);
this.lab1.Text = randchar[randNum].ToString();
lab1.ForeColor = Color.Red;
lab1.BackColor = Color.Transparent;
lab1.Font = new Font("黑体", 18);
Point p = new Point(rand.Next(0,this.Width), 0);
this.lab1.Location=p;
lab1.AutoSize = true;
this.Controls.Add(lab1);
Thread td = new Thread(new ThreadStart(movedown));
td.Start();
}
void movedown()
{
while (true)
{
Point p = new Point(this.lab1.Location.X, this.lab1.Location.Y + 1);
this.lab1.Location = p;
this.timer1.Enabled = false;
if (this.lab1.Location.Y == this.Height)
{
this.timer1.Enabled = true;
this.lab1.Dispose();
break;
} //这之后好象 没有触发timer事件,都没有字母掉掉下来,createLab()不执行 ?为什么呢
if (flag == 0)
break;
}
// this.lab1.Location.Y = this.lab1.Location.Y + 1;
}
#endregion
string s = "";
private void timer1_Tick(object sender, EventArgs e)
{
createLab();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
flag = 0;
}
}