Creating a form inside a form

I am new to Visual Studio 2010, and I plan to create a time tracking system. I just want to ask how I can create a form that makes up 2 forms in it. For example, if I click a button, it will open a new form inside the form. Please help. Thanks

+2
source share
5 answers

You must work with MDI (Multiple Document Interface), attach an article in this that may help.

+5
source
Form formA = new Form();
formA.IsMdiContainer = true;

Form formB = new Form();
formB.MdiParent = formA;
formB.Show();
+5
source

, , . MdiContainer/MDI , -

Mdi-Panel definiton:

MdiClientPanel: {    mdiForm;   private MdiClient ctlClient = new MdiClient();

public MdiClientPanel()
{
    base.Controls.Add(this.ctlClient);
}

public Form MdiForm
{
    get
    {
        if (this.mdiForm == null)
        {
            this.mdiForm = new Form();
            /// set the hidden ctlClient field which is used to determine if the form is an MDI form
            System.Reflection.FieldInfo field = typeof(Form).GetField("ctlClient", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            field.SetValue(this.mdiForm, this.ctlClient);
        }
        return this.mdiForm;
    }
}

}

:

/// mdiChildForm is the form that should be showed in the panel
/// mdiClientPanel is an instance of the MdiClientPanel
myMdiChildForm.MdiParent = mdiClientPanel1.MdiForm;
+3

I think this is a very simple way:

    Form1 form= new Form1 ();
    form.TopLevel = false;
    this.Controls.Add(form);
    form.Show();
+2
source

Maybe the MDI will do what you want.

Here is a tutorial for this.

+1
source

Source: https://habr.com/ru/post/1759606/


All Articles