C
Curtis Justus
Hi,
I currently have a control that is on a form [FormA] and I want to pass that
exact instance of the control to another form [FormB] (a child form that
appears on a button click). The control has state, etc. that works with
both forms.
In my button click on FormA, I take my control and pass it to a constructor
in FormB. Here is the code in the constructor:
public FormB(MyControl ctrl)
{
InitializeComponent();
_passedInControl = ctrl; /* used later to set the parent property
back to the original */
_oldParent = ctrl.Parent; /* used later to set the parent property
back to the original */
ctrl.Parent = this;
this.Controls.Add(ctrl);
}
I also have in the Form Closing event:
private void FormB_Closing(object sender, CancelEventArgs e)
{
if (this._passedInControl != null)
_passedInControl.Parent = _oldParent;
}
Here is my problem: my control doesn't appear on FormB. It disappears from
FormA (which should happen because the parent is changing) and it also
reappears on FormA after I close FormB. What do I need to do to get it to
appear on FormB?
Thanks in advance,
cj
I currently have a control that is on a form [FormA] and I want to pass that
exact instance of the control to another form [FormB] (a child form that
appears on a button click). The control has state, etc. that works with
both forms.
In my button click on FormA, I take my control and pass it to a constructor
in FormB. Here is the code in the constructor:
public FormB(MyControl ctrl)
{
InitializeComponent();
_passedInControl = ctrl; /* used later to set the parent property
back to the original */
_oldParent = ctrl.Parent; /* used later to set the parent property
back to the original */
ctrl.Parent = this;
this.Controls.Add(ctrl);
}
I also have in the Form Closing event:
private void FormB_Closing(object sender, CancelEventArgs e)
{
if (this._passedInControl != null)
_passedInControl.Parent = _oldParent;
}
Here is my problem: my control doesn't appear on FormB. It disappears from
FormA (which should happen because the parent is changing) and it also
reappears on FormA after I close FormB. What do I need to do to get it to
appear on FormB?
Thanks in advance,
cj