111,126
社区成员
发帖
与我相关
我的任务
分享 public partial class Form1 : Form
{
Point step = new Point(10, 10);
Rectangle picRec, clientRec;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
picRec.Offset(step);
if (picRec.X <= 0 || picRec.Right >= clientRec.Right)
{
step.X *= -1;
}
if (picRec.Y <= 0 || picRec.Bottom >= clientRec.Right)
{
step.Y *= -1;
}
pictureBox1.Location = picRec.Location;
}
private void button1_Click(object sender, EventArgs e)
{
picRec = new Rectangle(pictureBox1.Location, pictureBox1.Size);
clientRec = ClientRectangle;
Debug.Assert(clientRec.Contains(picRec));
timer1.Start();
}
}