110,538
社区成员
发帖
与我相关
我的任务
分享
private void frmMove_Load(object sender, EventArgs e)
{
pictureBox1.Location = new Point(0, 0);
}
public int x = 5;
public int y = 5;
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);
}