开始根据另一个图片框位置移动图片框 [英] Start moving the picturebox based on another picturebox location

查看:91
本文介绍了开始根据另一个图片框位置移动图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试移动图片框,但我想让其他图片框出现或者只在图片盒1到达特定位置后才开始移动。我正在使用计时器让它移动。我是新手,请理解:(



我尝试过:



private void timer1_Tick(object sender,EventArgs e)

{

picbox2.Left - = 5;

lbl2.Left - = 5;



if(picbox2.Left == 1245)//它的起始点是(1367,110)

{

lbl1.Left - = 5;

picbox1.Left - = 5;

}

}

I'm trying to move a picturebox but i want the other picturebox to appear or to start moving only after the picturebox1 gets to a specific location. Im using a timer to make it move. I am new to this thing, please understand :(

What I have tried:

private void timer1_Tick(object sender, EventArgs e)
{
picbox2.Left -= 5;
lbl2.Left -= 5;

if (picbox2.Left == 1245)//its staring point is (1367, 110)
{
lbl1.Left -= 5;
picbox1.Left -= 5;
}
}

推荐答案

如果它的起始位置是(1367,100),并且每次从它减去5,那么它将永远不会达到(1245,y):x坐标将永远以2或7结束,从不结束5.

我建议的是:

If it's starting location is (1367, 100), and you subtract 5 from it each time, then it will never reach (1245, y) at all: the x coordinate will always end in a 2 or a 7, never a 5.
What I'd suggest is :
if (picbox2.Left <= 1245)
   {
   ...
   }

就这样,它会当它到达那里时,它会移动,并从那一点开始继续移动。

That way, it will start moving when it gets there, and continue moving from that point.


这篇关于开始根据另一个图片框位置移动图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆