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) ||
(LastTextBox != _ribbonTextBox.TextBox))
{
// We only modify the parent and visible state if processing for correct container
if ((_ribbonTextBox.RibbonContainer.RibbonGroup.ShowingAsPopup && (parentControl is VisualPopupGroup)) ||
(!_ribbonTextBox.RibbonContainer.RibbonGroup.ShowingAsPopup && !(parentControl is VisualPopupGroup)))
{
// If we have added the custrom control to a parent before
if ((LastTextBox != null) && (LastParentControl != null))
{
// If that control is still a child of the old parent
if (LastParentControl.Controls.Contains(LastTextBox))
{
// Check for a collection that is based on the read only class
LastParentControl.Controls.Remove(LastTextBox);
}
}
// Remember the current control and new parent
LastTextBox = _ribbonTextBox.TextBox;
LastParentControl = parentControl;
// If we have a new textbox and parent
if ((LastTextBox != null) && (LastParentControl != null))
{
// Ensure the control is not in the display area when first added
LastTextBox.Location = new Point(-LastTextBox.Width, -LastTextBox.Height);
// Check for the correct visible state of the textbox
UpdateVisible(LastTextBox);
// Check for a collection that is based on the read only class
LastParentControl.Controls.Add(LastTextBox);
}
}
}
}