MDI Parent Form Problem setting Parent

眉间皱痕 提交于 2019-12-20 02:47:15

问题


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..........


回答1:


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.




回答2:


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.




回答3:


write this code in a parent form....

childform  obj = new childform( );
               obj.MdiParent = this;
               obj.StartPosition = FormStartPosition.CenterScreen;
               obj.Show( );


来源:https://stackoverflow.com/questions/4418604/mdi-parent-form-problem-setting-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!