How do I set a form's MdiParent property to the MdiParent when it is NOT
created by the MDIParent?
For example, frmMain creates frmA, frmA creates frmB .. how to make frmMain
the MdiParent of frmB?
private void btnAddNew_Click(object sender, EventArgs e)
{
frmB frmB = new frmB();
// this will not work
//frmEntry.MdiParent = frmMain;
frmEntry.Show();
this.Close();
}
Pritcham - 26 Jul 2006 11:35 GMT
Hi
If frmMain is your parent, and creates frmA then presumably you've set
frmA.MdiParent = me (from frmMain)? If you're then creating frmB from
frmA could you not do the following in frmA
frmB frmB = newfrmB()
frmB.MdiParent = frmMain
does that not work? I know you've said it doesn't but the code you've
shown is setting the MdiParent property of another form (frmEntry)
Martin
> How do I set a form's MdiParent property to the MdiParent when it is NOT
> created by the MDIParent?
[quoted text clipped - 10 lines]
> this.Close();
> }
Earl - 26 Jul 2006 21:02 GMT
Yes, that should've been frmB instead of frmEntry in the code. But no, that
does not work, setting frmB.MdiParent to frmMain ... Joris had the answer,
need to set the MdiParent of frmB to the MdiParent property of THIS form:
// making this assignment from frmA
frmB.MdiParent = this.MdiParent;
> Hi
>
[quoted text clipped - 25 lines]
>> this.Close();
>> }
Joris Zwaenepoel - 26 Jul 2006 14:24 GMT
If frmA has frmMain as its MDIParent, then you could write
frmB.MDIParent = Me.MDIParent
of if frmA is not a MDI Child form, maybe it has frmMain as its owner form,
then you can use:
frmB.MDiParent = frmA.Owner
Hope this helps,
Joris
> How do I set a form's MdiParent property to the MdiParent when it is NOT
> created by the MDIParent?
[quoted text clipped - 10 lines]
> this.Close();
> }
Earl - 26 Jul 2006 21:03 GMT
Thanks Joris, that is the right idea:
// making the assignment from frmA (which was created by frmMain)
frmB.MdiParent = this.MdiParent;
> If frmA has frmMain as its MDIParent, then you could write
>
[quoted text clipped - 25 lines]
>> this.Close();
>> }