110,556
社区成员
发帖
与我相关
我的任务
分享
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Interval = 500;
this.timer1.Start();
}
Random r = new Random();
private void timer1_Tick(object sender, EventArgs e)
{
Label l = new Label();
char cc = (char)((int)'A' + r.Next(26));
l.Text = cc.ToString();
l.Left = r.Next(this.Width);
this.Controls.Add(l);
foreach (Control c in this.Controls)
{
c.Top += 15;
if (c.Top == this.Height) c.Dispose();
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(Label))
{
Label t = (Label)c;
if (t.Text == e.KeyCode.ToString())
this.Controls.Remove(c);
}
}
}