Skip to main content
2 of 2
Control collections don't implement IEnumerable<T>, it turns out
Errorsatz
  • 1.4k
  • 8
  • 9

You have an error there, unless you wanted to include all child controls regardless of whether they're contained. It should be:

if (rect.IntersectsWith(ctl.Bounds)) 
{    
    Selected.Add(ctl);
    foreach (Control ct in ctl.Controls) 
    {
        Selected.Add(ct);
    }
}

As for the test, instead of two cases you can use:

if(rect.IntersectsWith(ctl.Bounds) == bContained)
Errorsatz
  • 1.4k
  • 8
  • 9