locked
How can I add a form into my main form RRS feed

  • Question

  •  

    hi all MSDN fans,

    I have a main form with MDI type and I stuck in with my  try to add a form ( nomal form, not MDI) into my MDI main form.

    Could I have any way to solve this problem?

    thank for your help. 

    Tuesday, May 22, 2007 2:03 AM

Answers

  • I think he wants to add the form as a control like you would any other control.  This is easily achieved.

    SomeForm myForm = new SomeForm();
    myForm.TopLevel = false;
    mainForm.Controls.Add(myForm);

    of course you would set the forms location, etc.  However, this is not recommended as it eats away at system resources.  You should look into making a user control.  There are plenty of examples on MSDN.
    Monday, June 4, 2007 11:11 PM

All replies

  • Create a new instance of the MDI child template form

     

    Form2 chForm = new Form2();

     

    Set parent form for the child window

    chForm.MdiParent=this;

     

    Display the child window

    chForm.Show();

     

    Hope this will help you.

    Tuesday, May 22, 2007 2:17 AM
  • Thank for your reply

     

    but it is not my problem ( may be because of Language)

     

    for example,  you often add a button in your form

    now i would like to add a another form into my current form. and I dont know how to do it...

    thanks you so much.

    DongMT 

    Monday, June 4, 2007 7:36 AM
  • Hi,

     

    Add following code set to the button click event handler will popup the second form.

     

    Code Snippet

    Form2 chForm = new Form2();

    chForm.MdiParent=this;

    chForm.Show();

     

    _xx

    Monday, June 4, 2007 10:38 PM
  • I think he wants to add the form as a control like you would any other control.  This is easily achieved.

    SomeForm myForm = new SomeForm();
    myForm.TopLevel = false;
    mainForm.Controls.Add(myForm);

    of course you would set the forms location, etc.  However, this is not recommended as it eats away at system resources.  You should look into making a user control.  There are plenty of examples on MSDN.
    Monday, June 4, 2007 11:11 PM
  •  Thank  Ðãvę S. Âņđęŕŝőŋ

    your thought is right, and may i need to save system resources and bay be better if write a usercontrol, thank for your advice.

     

    Wednesday, June 6, 2007 1:18 AM