Question

I am using a MDI parent form that has a childs and they show up very well when they are called up by this parent and i use to intensiate child form as

ChildForm child = new ChildForm();
child.IsMdiContainer= this;
child.Show();

works well as soon as they are called from parent control but if i call them from another form that is not child of any parent form then they no longer remains child of main parent one obvious reason is that when i intensiate them on that independent form is that I simply cannot use child.MDIParent = this; because it will tend to make independent form parent but i also have tried

MDIParentForm form = new MDIParentForm 

ChildForm child = new ChildForm();
child.IsMdiContainer= form ;
child.Show();

but this also dose not help instead of this it throws an exception that the form that I am trying to set Parent is not MDI Container then to this I give a try and modify

MDIParentForm form = new MDIParentForm ;
form.IsMdiContainer= true;
ChildForm child = new ChildForm();
child.MDIParent = form ;
child.Show();

and in its result nothing appears

Any idea how to..........

Was it helpful?

Solution

To create a child from another child, just write it like this:

ChildForm sibling = new ChildForm();
sibling.MdiParent = this.MdiParent;
sibling.Show();

Or fire a custom event that the parent can respond to.

OTHER TIPS

You should set the Parent to be the already existing mdiform, not create a new one.

If there isn't an instance of the mdiform already, you should not only create an instance of the form, but also show it.

var mdiForm = new MdiForm();
mdiForm.IsMdiContainer = true;
var childForm = new ChildForm();
childForm.MdiParent = mdiForm;
mdiForm.Show();
childForm.Show();

Also notice that I use mdiForm.IsMdiContainer, AFAIK there is no IsMdiParent property.

write this code in a parent form....

childform  obj = new childform( );
               obj.MdiParent = this;
               obj.StartPosition = FormStartPosition.CenterScreen;
               obj.Show( );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top