C#打字游戏

发布时间:2009年06月04日      浏览次数:1180 次
//打字游戏
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Interval = 500; //定时0.5秒
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)); //随机产生26 个字母
l.Text = cc.ToString();
//l.BackColor = Color.Red;
l.ForeColor = Color.Red;
l.Left = r.Next(this.Width); //随机水平位置
this.panel1.Controls.Add(l);
foreach (Control c in this.panel1.Controls)
{
c.Top += 15; //向下移动
if (c.Top == this.Height) c.Dispose(); //到底消除
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
foreach (Control c in this.panel1.Controls)
{
if (c.GetType() == typeof(Label))
{
Label t = (Label)c;
if (t.Text == e.KeyCode.ToString()) //按下的键有, 消除
this.panel1.Controls.Remove(c);
}
}
}
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!