日期:2014-05-17 浏览次数:20880 次
private void timer1_Tick(object sender, EventArgs e)
{
int f_x = panel1.Width;
int f_y = panel1.Height;
int p_x = pictureBox1.Location.X;
int p_y = pictureBox1.Location.Y;
if (p_x >= (f_x-pictureBox1.Width)) //右边超出窗体大小 除去运动物体的宽
x = -5;
else if (p_x <= 0) //左边超出窗体大小
x = 5;
if (p_y >= (f_y-pictureBox1.Height)) //下边边超出窗体大小 除运动物体的高
y = -5;
else if (p_y <= 0) //上边超出窗体大小
y = 5;
pictureBox1.Location = new Point(pictureBox1.Location.X + x, pictureBox1.Location.Y + y);
}