日期:2014-05-18 浏览次数:20923 次
PictureBox p2 = new PictureBox();
PictureBox p1 = new PictureBox();
private void Form1_Load(object sender, EventArgs e)
{
p1.BackColor = Color.Black;
p1.Width = 30;
p1.Height = 20;
p1.Top = 5;
this.Controls.Add(p1);
p2.BackColor = Color.Red;
p2.Width = 30;
p2.Height = 20;
p2.Top = 30;
this.Controls.Add(p2);
p1x = (float)p1.Left;
p2x = (float)p2.Left;
Timer t=new Timer();
t.Interval=(40);
t.Tick +=new EventHandler(t_Tick);
t.Start();
}
float p1x;
float p2x;
private void t_Tick(object s, EventArgs e)
{
p1x =p1x+ (float)2 / 25;
p2x = p2x + (float)10 / 25;
this.p1.Left = (int)p1x;
this.p2.Left = (int)p2x;
}