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