I want my UserControl to automatically update its Region property. I want it to be a combination of child controls' regions merged together.
Here what I have so far:
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
Region region = new Region(new Rectangle(Point.Empty, Size.Empty));
foreach (Control control in Controls)
{
if (control.Region != null)
region.Union(control.Region);
else
region.Union(control.Bounds);
}
Region = region;
Invalidate();
}
Problem is that it does not work: Line region.Union(control.Region);
must be changed because Region does not include information about left and top offset of the control.
What can I do?