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