Muhammad Adeel

Muhammad Adeel

  • NA
  • 55
  • 14.1k

Collision from boundaries of form.

Jan 25 2015 1:49 AM
I have made two circles of same size on windows form application and then moved them in such a way that they will never be collided and now i want circles to reflect from boundaries of Form how this could be done in a easy way.
 
private void button11_Click(object sender, EventArgs e)
{
Pen myPen = new Pen(Color.Black);
Pen mypen2 = new Pen(Color.Black);
Graphics formGraphics;
formGraphics = this.CreateGraphics();
int x=100, y=100,x1=200,y1=200;
for (int i = 2; i < 200; i++)
{
this.Refresh();
formGraphics = this.CreateGraphics();
formGraphics.DrawEllipse(myPen, new Rectangle(x + i, y/ i, 100, 100));
formGraphics.DrawEllipse(myPen, new Rectangle(x1 / i, y1 + i, 100, 100));
System.Threading.Thread.Sleep(22);
}