开发者

MDI Parent Form Problem setting Parent

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();
c开发者_如何学Pythonhild.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..........


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.


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


class MainClass
{
   public string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
   public void showWindow(Form openWin, Form closeWin, Form MDI)
    {
        closeWin.Close();
        openWin.WindowState = FormWindowState.Minimized;
        openWin.MdiParent = MDI;
        openWin.Show();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜