How to Put a Form Inside a Form Using C#

In this tutorial, I will teach you how to add a form inside the form using C#. This method has the ability to change the display and how the form works into an MDI parent form. Then, you will see that the form displays a sunken client area with a raised border, once you set this property into true . And in the client area, it is where all the MDI child forms placed to the parent form are displayed.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application. addfor1

Step 2

Do the Form just like this. addfor2

Step 3

Add another Form. addfor3

Step 4

Go to Form1 and open the code view. In the code view create a method for closing and adding the form inside the form.
  1. private void closeChildForm()
  2.         {
  3.             foreach(Form frm in this.MdiChildren)
  4.             {
  5.                 frm.Close();
  6.             }
  7.         }
  8.  
  9.         private void showFrm(Form frm)
  10.         {
  11.             this.IsMdiContainer = true;
  12.             frm.MdiParent = this;
  13.             frm.Show();
  14.         }

Step 5

Double click the “Add Form” button and call the method that you have created to execute when the button is clicked.
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             closeChildForm();
  4.             Form frm = new Form2();
  5.             showFrm(frm);
  6.  
  7.         }
For more question about this article. You can contact me @ Email – [email protected] Mobile No. – 09305235027 – TNT FB Account – https://www.facebook.com/onnaj.soicalap Or feel free to comment below

Add new comment