我迭代我的表格"选择"包含给定矩形的所有控件。我使用以下内容:
List<Control> getControls(Control container, Rectangle rect)
{
rect = RectangleToClient(rect);
controlSelection = new List<Control>();
foreach (Control ctl in container.Controls)
if (rect.Contains(ctl.Bounds))
{
controlSelection.Add(ctl);
foreach (Control ct in ctl.Controls) controlSelection.Add(ct);
}
return controlSelection;
}
如何更改它,选择一个控件,即使它只是在给定的矩形内?