Skip to main content
deleted 15 characters in body
Source Link
user33306
user33306

You can make things more concise with LINQ. Here's one way that should work:

List<Control> getControls(Control container, Rectangle rect, bool bContained = false)
{
    rect = RectangleToClient(rect);
    return (from Control ctl in container.Controls
                  where rect.IntersectsWith(ctl.Bounds) == bContained
                  let ctls = new List<Control> { 
 ctl }.Union(ctl.Controls.OfType<Control>())                select new List<Control> { ctl }.Union(ctl.Controls.OfType<Control>()))
                  select ctls).SelectMany(x => x).ToList();
}

This basically does the same thing, filters the collection according to bContained. Creates a collection of lists that each contain the parent control and its sub-controls. Then flattens them into one list.

You can make things more concise with LINQ. Here's one way that should work:

List<Control> getControls(Control container, Rectangle rect, bool bContained = false)
{
    rect = RectangleToClient(rect);
    return (from Control ctl in container.Controls
                  where rect.IntersectsWith(ctl.Bounds) == bContained
                  let ctls = new List<Control> { ctl }.Union(ctl.Controls.OfType<Control>())                     
                  select ctls).SelectMany(x => x).ToList();
}

This basically does the same thing, filters the collection according to bContained. Creates a collection of lists that each contain the parent control and its sub-controls. Then flattens them into one list.

You can make things more concise with LINQ. Here's one way that should work:

List<Control> getControls(Control container, Rectangle rect, bool bContained = false)
{
    rect = RectangleToClient(rect);
    return (from Control ctl in container.Controls
                  where rect.IntersectsWith(ctl.Bounds) == bContained                      
                  select new List<Control> { ctl }.Union(ctl.Controls.OfType<Control>()))
                  .SelectMany(x => x).ToList();
}

This basically does the same thing, filters the collection according to bContained. Creates a collection of lists that each contain the parent control and its sub-controls. Then flattens them into one list.

Source Link
user33306
user33306

You can make things more concise with LINQ. Here's one way that should work:

List<Control> getControls(Control container, Rectangle rect, bool bContained = false)
{
    rect = RectangleToClient(rect);
    return (from Control ctl in container.Controls
                  where rect.IntersectsWith(ctl.Bounds) == bContained
                  let ctls = new List<Control> { ctl }.Union(ctl.Controls.OfType<Control>())                     
                  select ctls).SelectMany(x => x).ToList();
}

This basically does the same thing, filters the collection according to bContained. Creates a collection of lists that each contain the parent control and its sub-controls. Then flattens them into one list.