MDI form with child and child-child forms
-
Hi All, For a few weeks now i am strungling with an anoying issue. I have a MDI Parent form. From this form i have child forms (normal winforms) which i open. These forms are opened withing the MDI parent form. So far so so good. And know my problem. From this childform i open a new form through a button. There is for me no way to open this form as mdi child form because its parent is also an mdi child. I have looked for looping throug form collections but cannot find the solution to my problem. How can i detect the MDI Parent of my application from within all open forms. Thanks Marcel Vreuls
Kind regards, Marcel Vreuls MarcelVreuls.com <<A good idea can change your life>>
-
Hi All, For a few weeks now i am strungling with an anoying issue. I have a MDI Parent form. From this form i have child forms (normal winforms) which i open. These forms are opened withing the MDI parent form. So far so so good. And know my problem. From this childform i open a new form through a button. There is for me no way to open this form as mdi child form because its parent is also an mdi child. I have looked for looping throug form collections but cannot find the solution to my problem. How can i detect the MDI Parent of my application from within all open forms. Thanks Marcel Vreuls
Kind regards, Marcel Vreuls MarcelVreuls.com <<A good idea can change your life>>
Well, since you should know the parent form's class name this is what I've done recently. I can't guarantee that it is the best method of doing it but I also haven't found any other solution:
// Child form
private void Button1_Click(object sender, EventArgs e)
{
// Do some stuff
// ...// Now open a new child form by calling a method in the MDI parent form ((AppForm)this.MdiParent).SomeMethodToOpenChild();
}
Casting the current child form's 'Form MdiParent' to the application's form type, then calling a method that opens the necessary child window. Like I said, I don't know how safe that is. But I believe you could check ahead of time like this:
if (this.MdiParent is AppForm)
((AppForm)this.MdiParent).SomeMethodToOpenChild();I hope this at least gets you going in the right direction. :-)
-
Hi All, For a few weeks now i am strungling with an anoying issue. I have a MDI Parent form. From this form i have child forms (normal winforms) which i open. These forms are opened withing the MDI parent form. So far so so good. And know my problem. From this childform i open a new form through a button. There is for me no way to open this form as mdi child form because its parent is also an mdi child. I have looked for looping throug form collections but cannot find the solution to my problem. How can i detect the MDI Parent of my application from within all open forms. Thanks Marcel Vreuls
Kind regards, Marcel Vreuls MarcelVreuls.com <<A good idea can change your life>>
If the form is an MdiChild, you can get a reference to its parent using the MdiParent property. If you want to set another form as a child of the same parent, it's pretty easy If you want a MdiChild form to be both a MdiChild to one Parent and a MdiParent to another child form, you can't. It's not supported. A form cannot be both a MdiChild and MdiParent at the same time.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
If the form is an MdiChild, you can get a reference to its parent using the MdiParent property. If you want to set another form as a child of the same parent, it's pretty easy If you want a MdiChild form to be both a MdiChild to one Parent and a MdiParent to another child form, you can't. It's not supported. A form cannot be both a MdiChild and MdiParent at the same time.
A guide to posting questions on CodeProject[^]
Dave KreskowiakGreat answer Dave. :thumbsup:
The mind is like a parachute. It doesn’t work unless it’s open.