开发者

Making a normal form as MDI

I am working on a application in which I have to show different forms stacked one upon the other. Due to some restrictions, I cannot use MDI and also it has a lot of issues.

I am able to get what I want but with a problem. The forms will be stacked, but they do not remain in the parent form. Lets take it by an example. The structure goes like this. 1) There is a form A (My parent form) 2) a second form "B" opens on a button click event on Form "A". (Note: B.ShowInTaskBar=False) 3) again, a third form "C" opens on a button click event on F开发者_JS百科orm "B". (Note: C.ShowInTaskBar=False)

Now, when I minimize form A, it gets minimized but the Form B and C, remains as it is. I want them to get minimized at the same time. I want form B and C should remain as a child form of form A.

How to get that.


Just use MDI forms. There is no technical restriction about FormBorderStyle's value for MDI children. Remember to set the IsMdiContainer property to true for the parent form and then set the child form's MdiParent property to the parent form before Show() is called.

Edit: I'm not exactly sure what you mean by stacking. You can easily control the child positions if that is what you mean:

public void ShowChildren()
{
    Child child1 = new Child();
    Child child2 = new Child();

    child1.MdiParent = this;
    child2.MdiParent = this;

    child1.Show();
    child2.Show();

    child1.Size = new System.Drawing.Size(100, 100);
    child1.Location = new System.Drawing.Point(0, 0);
    child2.Size = new System.Drawing.Size(100, 100);
    child2.Location = new System.Drawing.Point(0, 100);
}

Edit #2: Are you trying to nest the forms? If so you can make the parent a normal form and place a UserControl A in the parent. Then place UserControl B in UserControl A. Allowing the user to move these around becomes more difficult, but if you already wanted no border this may not be an issue for you.


public void formMain_buttonShowA_click() {
    FormA formA = new FormA();
    formA.ShowDialog();
}

public void formA_buttonShowB_click() {
   FormB formB = new FormB();
   formB.ShowDialog();
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜