Home

Creating an MDI Application in Microsoft Visual Studio 2013

Introduction

Microsoft Visual Studio 2013 make it very easy to start an MDI application. It doesn't do everything for you but it provides all the primary characteristics. It does this through the MDI Parent Form of the Add New Item dialog box.

 

ApplicationTopic Applied: Creating an MDI Application in Microsoft Visual Studio

  1. Application 1:
    1. To start a new application, on the Standard toolbar, click the New Project button New Project
    2. In the middle list, click Empty Project
    3. Set the Name to Announce
    4. Click OK
    5. On the main menu, click PROJECT -> Announce Properties...
    6. Change Output Type to Windows Application
    7. To add a new form, on the main menu, click PROJECT -> Add Windows Form...
    8. Make sure Windows Form is selected in the middle list.
      Set the Name to SampleDocument
    9. Click Add
    10. From the Common Controls section of the Toolbox, click TextBox and click the form
    11. Using the Properties window, change the textbox's characteristics as follows:
      (Name):      Information
      Dock:         Fill
      Multiline:   True
      ScrollBars: Vertical
    12. To add a new form, on the main menu, click PROJECT -> Add New Item...
    13. In the middle list, click MDI Parent Form

      Add New Item

    14. Set the Name to ParentDocument
    15. Click Add
    16. In the Properties window, change Text to Journal Announcement
    17. Right-click the form (anywhere on the form) and click View Code
    18. Change the document as follows:
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      
      namespace Announce
      {
          public partial class ParentDocument : Form
          {
              private int childFormNumber = 1;
      
              public ParentDocument()
              {
                  InitializeComponent();
      
                  ShowNewForm(null, null);
              }
      
              private void ShowNewForm(object sender, EventArgs e)
              {
                  SampleDocument childForm = new SampleDocument();
                  childForm.MdiParent = this;
                  childForm.Text = "Untitled " + childFormNumber++;
                  childForm.Show();
              }
      
              . . . No Change
      
              private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
              {
                  foreach (Form childForm in MdiChildren)
                  {
                      childForm.Close();
                  }
              }
      
              [STAThread]
              static void Main()
              {
                  Application.EnableVisualStyles();
                  Application.SetCompatibleTextRenderingDefault(false);
                  Application.Run(new ParentDocument());
              }
          }
      }
    19. Execute the application to see the result

      Multiple Document Interface

    20. Close the application and return to your programming environment
  2. Application 2:
    1. To start a new application, on the main menu, click FILE -> New -> Project...
    2. In the middle list, click Windows Form Application
    3. Set the Name to GreyViewer
    4. Click OK
    5. In the Solution Explorer, right-click Form1.cs and click Rename
    6. Change the name to SingleView.cs and press Enter twice
    7. To add a new form, on the main menu, click PROJECT -> Add New Item...
    8. In the middle list, click MDI Parent Form
    9. Set the Name to Producer
    10. Click Add
    11. Click the title bar of the form to make sure it is selected.
      In the Properties window, click the Events button Events and double-click Load
    12. Change the document as follows:
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      
      namespace GreyViewer
      {
          public partial class Producer : Form
          {
              private int childFormNumber = 1;
      
              public Producer()
              {
                  InitializeComponent();
              }
      
              private void ShowNewForm(object sender, EventArgs e)
              {
                  SingleView childForm = new SingleView();
                  childForm.MdiParent = this;
                  childForm.Text = "Viewer " + childFormNumber++;
                  childForm.Show();
              }
      
              . . . No Change
      
              private void Producer_Load(object sender, EventArgs e)
              {
                  ShowNewForm(sender, e);
              }
          }
      }
    13. In the Solution Explorer, double-click Program.cs and change the document as follows:
      [STAThread]
      static void Main()
      {
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
          Application.Run(new Producer());
      }
    14. Execute the application to see the result
  3. Close Microsoft Visual Studio
 

Home Copyright © 2014-2022, FunctionX