最近没事设计一个电梯的模拟程序.在一个panel里面有2个picturebox.分别代表左边门和右边门.
代码如下:
private void timer1_Tick(object sender, EventArgs e)
{ Point PL = new Point(this.pictureBox1.Location.X - 1, 0); //PL代表左边门的位置 初始位置(0,0), 左边门往左,-1
Point PR = new Point(this.pictureBox2.Location.X + 1, 0); //PR代表右边门的位置 初始位置(92,0), 右边门往右,+1
if (PL.X == -92)
{
timer1.Enabled = false;
}
}
问题是就是运行后它不会移动.已经设置为true,interval=10.
代码如下:
private void timer1_Tick(object sender, EventArgs e)
{ Point PL = new Point(this.pictureBox1.Location.X - 1, 0); //PL代表左边门的位置 初始位置(0,0), 左边门往左,-1
Point PR = new Point(this.pictureBox2.Location.X + 1, 0); //PR代表右边门的位置 初始位置(92,0), 右边门往右,+1
if (PL.X == -92)
{
timer1.Enabled = false;
}
}
问题是就是运行后它不会移动.已经设置为true,interval=10.
{
this.pictureBox1.Location.X-=1;
this.pictureBox2.Location.X+=1;
this.pictureBox1.Refresh();
this.pictureBox2.Refresh();
if (this.pictureBox1.X== -92)
{
timer1.Enabled = false;
}
}
//Refresh();//强制控件重绘