private void ChangeParent (Control new_parent)
{
bool pre_enabled;
bool pre_visible;
Font pre_font;
Color pre_fore_color;
Color pre_back_color;
RightToLeft pre_rtl;
// These properties are inherited from our parent
// Get them pre parent-change and then send events
// if they are changed after we have our new parent
pre_enabled = Enabled;
pre_visible = Visible;
pre_font = Font;
pre_fore_color = ForeColor;
pre_back_color = BackColor;
pre_rtl = RightToLeft;
// MS doesn't seem to send a CursorChangedEvent
parent = new_parent;
if(Offset != Point.Empty)
UpdateBounds();
Form frm = this as Form;
if (frm == null && IsHandleCreated)// && !(this is ToolStrip))
{
IntPtr parent_handle = IntPtr.Zero;
if (new_parent != null && new_parent.IsHandleCreated)
new_parent.NSViewForControl.AddSubview (this);
else
this.NSViewForControl.RemoveFromSuperview ();
}
else if (new_parent is Form)
{
//var form = (Form)new_parent;
//form.m_helper.Toolbar = (ToolStrip)this;
//form.m_helper.Toolbar.Visible = true;
//form.m_helper.ShowsToolbarButton = true;
}
OnParentChanged (EventArgs.Empty);
if (pre_enabled != Enabled)
{
OnEnabledChanged (EventArgs.Empty);
}
if (pre_visible != Visible)
{
OnVisibleChanged (EventArgs.Empty);
}
if (pre_font != Font)
{
OnFontChanged (EventArgs.Empty);
}
if (pre_fore_color != ForeColor)
{
OnForeColorChanged (EventArgs.Empty);
}
if (pre_back_color != BackColor)
{
OnBackColorChanged (EventArgs.Empty);
}
if (pre_rtl != RightToLeft)
{
// MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
// because when RTL changes they have to recreate the win32 control
// We don't really need that (until someone runs into compatibility issues)
OnRightToLeftChanged (EventArgs.Empty);
}
if ((binding_context == null))
{
OnBindingContextChanged (EventArgs.Empty);
}
}