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

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();
}
 
P

Pritcham

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
 
G

Guest

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
 
E

Earl

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;
 
E

Earl

Thanks Joris, that is the right idea:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top