How to Put a Form Inside a Form Using C#

Submitted by: 
Language: 
Visitors have accessed this post 186 times.

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

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.