Each control has a
Top
,
Left
,
Width
and
Height
property. When a user selects a control, you will need to determine these properties, and then cycle through all the other controls to check if there is an intersection. You can use a foreach loop on the form's controls, something like this:-
Rectangle sr = new Rectangle(panel1.Left, panel1.Top, panel1.Width, panel1.Height);
foreach (Control ctrl in this.Controls)
{
if (ctrl is Panel && ctrl != panel1)
{
Rectangle r = new Rectangle(ctrl.Left, ctrl.Top, ctrl.Width, ctrl.Height);
if (sr.IntersectsWith(r))
{
}
}
}
I have just used
panel1
as an example. You should substitute for your selected panel.