Jak chcesz ładnie i estetycznie zrób sobie klasę Rectangle (prostokąt) i tam trzymaj jego rozmiar i współrzędne boków. Każdemu panelowi przypisujesz własny Rectangle i napisz sobie jeszcze metodę do sprawdzania czy się styka jeden z drugim. Coś takiego:
class Rectangle
{
private int width, height;
private int x, y;
public int X
{
get { return x; }
} // odpowiada również lewej krawędzi (left)
public int Y
{
get { return y; }
} // odpowiada również górnej krawędzi (top)
public int Width
{
get { return width; }
}
public int Height
{
get { return height; }
}
public int Right
{
get { return x + width; }
}
public int Bottom
{
get { return y + height; }
}
public Rectangle(int x, int y, int width, int height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public bool Intersects(Rectangle rectangle)
{
if ((rectangle.X >= this.X && rectangle.X <= this.Right) && (rectangle.Y >= this.Y && rectangle.Y <= this.Bottom))
return true;
else
return false;
}
}
Jeżeli nie potrzebne ci są właściwości tego prostokąta na zew., a tylko metoda Intersects to wywal wszystkie prócz Right i Bottom, które zmień na prywatne.