private void UpdateParent(Control parentControl)
{
// Is there a change in the textbox or a change in
// the parent control that is hosting the control...
if ((parentControl != LastParentControl) ||
(LastTrackBar != _ribbonTrackBar.TrackBar))
{
// We only modify the parent and visible state if processing for correct container
if ((_ribbonTrackBar.RibbonContainer.RibbonGroup.ShowingAsPopup && (parentControl is VisualPopupGroup)) ||
(!_ribbonTrackBar.RibbonContainer.RibbonGroup.ShowingAsPopup && !(parentControl is VisualPopupGroup)))
{
// If we have added the custrom control to a parent before
if ((LastTrackBar != null) && (LastParentControl != null))
{
// If that control is still a child of the old parent
if (LastParentControl.Controls.Contains(LastTrackBar))
{
// Check for a collection that is based on the read only class
LastParentControl.Controls.Remove(LastTrackBar);
}
}
// Remember the current control and new parent
LastTrackBar = _ribbonTrackBar.TrackBar;
LastParentControl = parentControl;
// If we have a new textbox and parent
if ((LastTrackBar != null) && (LastParentControl != null))
{
// Ensure the control is not in the display area when first added
LastTrackBar.Location = new Point(-LastTrackBar.Width, -LastTrackBar.Height);
// Check for the correct visible state of the textbox
UpdateVisible(LastTrackBar);
// Check for a collection that is based on the read only class
LastParentControl.Controls.Add(LastTrackBar);
}
}
}
}