I have a user control that contains a collection of controls to be reused for presenting data on the UI. I've attempted implementing a "pop-out" option that will re-parent the control from another container on the form (a Panel, for example), create a new tab page, and then add the control to the tab page.
Unfortunately, when the control is added to the TabPage, its size appears to be locked to the way it was presented with the last parent.
I overrode the ParentChanged event to detect when the control was actually added to the TabPage. If I examine the size, attempt to set the size to the TabPage's ClientRectangle, and then re-examine the size - it does not change. Setting the Dock property does not alter this behavior (especially Fill).
protected override void OnParentChanged(EventArgs e)
{
if (this.Parent != null)
{
Size oldSize = this.Size;
this.Size = this.Parent.ClientRectangle.Size;
if (this.Size == oldSize)
{
// this is where we end up
throw new Exception("We didn't change size!");
}
}
}