Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
programming4us
Windows 7

Visual Studio 2010 : Building the Windows Container (part 3) - Creating a Multiple Document Interface

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
7/2/2011 4:09:09 PM

4. Creating a Multiple Document Interface

You may have used a Windows application where all the application windows are contained within a parent window. An application in which all child windows are contained within a parent window is a Multiple Document Interface (MDI).

Creating an MDI application involves these high-level steps:

  1. Create the parent container form.

  2. Create child forms.

  3. Write code that opens the child forms in the container.

To create the parent MDI form, follow these steps:

  1. Create a new Windows application in Visual Basic.

    Visual Studio creates a new Windows project with an empty Windows Form named Form1.

  2. Set the Form1 IsMdiContainer property to True.

  3. Add a MenuStrip control to the form.

  4. Add the menu items Select and Window.

  5. Add the menu items Open Form 2 and Open Form 3 to the Select menu.

After you have the parent form, create these child forms to open in the parent MDI form:

  1. Add a new form named Form2.

  2. Add a label and a text box to the form.

  3. Add a new form named Form3.

  4. Add a MonthCalendar control to the form.

In the parent MDI container Form1, follow these steps:

  1. Double-click the form to access the form's Load event.

  2. Above the Load event, type this line:

    Dim frmChild As Form

  3. In the Load event, type this line:

    • VB

      MenuStrip1.MdiWindowListItem = WindowToolStripMenuItem

    • C#

      MenuStrip1.MdiWindowListItem = WindowToolStripMenuItem;

      This line sets the Windows menu item as the MdiWindowListItem control for the menu strip. As child windows are opened, the Windows menu displays the windows, along with a check mark, next to the active window.

  4. Below the Load event, type these lines:

    • VB

      Private Sub GetChild(ByRef frmChild As Form)
      frmChild.MdiParent = Me
      frmChild.Show()
      End Sub

    • C#

      private void GetChild(ref Form frmChild)
      {
      frmChild.MdiParent = this;
      frmChild.Show();
      }

      This code sample creates a procedure named GetChild that accepts a child form as a parameter. When the child form is passed to GetChild, the procedure sets the child form's MDI parent container as the displayed form and displays the child form in the container.

  5. In the Windows Forms Designer, double-click the Open Form 2 menu item.

    The Click event is created.

  6. Type this line in the Click event:

    GetChild(New Form2)

    This line passes Form2 to the GetChild procedure.

  7. Repeat Steps 4 and 5 for the Form 3 menu item and substitute Form3 for Form2 in the code.

The entire code sample (minus the hidden code that Visual Studio creates) for Form1 is shown in Listing 1.

Listing 1. Code That Services the Multiple Document Interface
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.
EventArgs) Handles MyBase.Load
MenuStrip1.MdiWindowListItem = WindowToolStripMenuItem
End Sub



Private Sub GetChild(ByRef frmChild As Form)
frmChild.MdiParent = Me
frmChild.Show()
End Sub

Private Sub OpenForm2ToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles OpenForm2ToolStripMenuItem.Click
GetChild(New Form2)
End Sub

Private Sub OpenFormToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles OpenFormToolStripMenuItem.Click
GetChild(New Form3)
End Sub
End Class


To test the MDI application, follow these steps:

  1. Press Ctrl+F5 to run the application.

  2. Choose the Select menu item.

  3. Choose Open Form 2 from the Select menu.

    Form2 opens and is contained within the parent form.

  4. Repeat Steps 1-3 to open Form3.

  5. Click the Windows menu.

    The Windows menu displays the open windows. A check mark appears next to the active window, as shown in Figure 10.

Figure 10. Use the Windows menu to manage child windows.

4.1. Taking advantage of visual inheritance

Sometimes, you want to reuse forms. You can inherit from an existing form rather than create forms from scratch. You need two forms: the base form and one to inherit from the base form.

To create the base form, follow these steps:

  1. Open the Add New Item window and add a new Windows Form to the project.

    You can press Ctrl+Shift+A to open the Add New Item window.

  2. Add a label and a text box to the form.

  3. Choose BuildBuild Solution.

You must build the base form in order to inherit from it.


To inherit from the base form, follow these steps:

  1. Choose Project=>Add New Item.

    The Add New Item window appears.

  2. Click the Inherited Form template.

  3. Enter a name for the form.

  4. Click Add.

    The Inheritance Picker appears.

  5. Click the base form in the Inheritance Picker.

  6. Click OK.

    The inherited form displays the base form's controls.

NOTE

You must build your solution whenever you make changes to the base form in order to make changes appear in the inherited form.

Other -----------------
- Visual Studio 2010 : Building the Windows Container (part 1) - Setting common form properties & Creating dialog boxes
- Microsoft Visio 2010 : Adding Labels to Flowcharts & Understanding Swimlane Diagrams
- Microsoft Visio 2010 : Selecting a Flowchart Type & Creating Flowcharts
- Automating the Windows 7 Installation : Choosing Automated Deployment Options (part 3) - An Overview of the System Preparation Tool and Disk Imaging
- Automating the Windows 7 Installation : Choosing Automated Deployment Options (part 2)
- Automating the Windows 7 Installation : Choosing Automated Deployment Options (part 1) - An Overview of the Microsoft Deployment Toolkit 2010
- Advanced .NET Framework with VB 2010 : Coding Attributes - Reflecting Attributes
- Advanced .NET Framework with VB 2010 : Coding Attributes - Coding Custom Attributes
- Advanced .NET Framework with VB 2010 : Coding Attributes - Applying Attributes
- Microsoft Visio 2010 : Adding Sophistication to Your Drawings - Working with Background Pages and Borders
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server