Setting MdiParent property on a form created by another non-Mdi form

  • Thread starter Thread starter Earl
  • Start date Start date
E

Earl

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();
}
 
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
 
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
 
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;
 
Thanks Joris, that is the right idea:

// making the assignment from frmA (which was created by frmMain)
frmB.MdiParent = this.MdiParent;
 
Back
Top