MDI Applications in Visual Basic .NET

In this article, I will explain you about MDI Applications in Visual Basic .NET.
  • 6014

In this article, I will explain you about MDI Applications in Visual Basic .NET. 

In Visual Basic .NET when we need to work with several documents at once then we use MDI (Multiple Document Interface) Application. We use MDI application where the user might like to have multiple forms or documents open concurrently. In most real time applications we often find that multiple windows open within another window. This can be done by implementing Multiple Document Interface (MDI) Applications. MDI is also handy when your application is too large, and you want to provide a simple mechanism for closing all the child forms when the user exits the application. Microsoft Excel is the example of an MDI application because it allows us to work with several documents same time. Microsoft Word is the example of Single Document Interface (SDI)applications which allows us to work with a single document at once.

Creating MDI Applications

In Visual Basic .NET see how we create an MDI application. Open a new Windows Application in which there is a form named Form1. Add another form, Form2 to this application for this you have to right-clicking on the project name in Solution Explorer and select Add->Add Windows Form.We will make From1 as the MDI parent window and Form2 as MDI child window. To make Form1as MDI parent select Form1 and in its Properties Window, set the property IsMdiContainer toTrue.


Once you set that property to true the Form1 acts like an MDI container for the child forms. It also changes its color and look like the image below:


Now, from the toolbox drag a MenuStrip onto Form1. We will display child windows when a menu item is clicked. Name the top-level menu item to New with submenu items as New Child Window, Arrange Child Window and Exit.


Public Class Form1
    Dim ChildF As Integer = 0
    Dim ChildForms(6) As Form2
    'Declaring an array to store child windows
    'Six child windows (Form2) will be displayed
    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.ObjectByVal e AsSystem.EventArgs)

 Handles NewToolStripMenuItem.Click
        ChildF += 1
        ChildForms(ChildF) = New Form2()
        ChildForms(ChildF).Text = "ChildForm" & Str(ChildF)
        'Setting title for child forms and incrementing the number with an array
        ChildForms(ChildF).MdiParent = Me
    End Sub
    Private Sub ArrangeChildWindowToolStripMenuItem_Click(ByVal sender As System.ObjectByValAs System.EventArgs)

Handles ArrangeChildWindowToolStripMenuItem.Click
        'Arranging child windows on the parent form with predefined LayoutMdi method
        'Different layouts available are, ArrangeIcons, Cascade, TileHorizontal, TileVertica
    End Sub
    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.ObjectByVal e AsSystem.EventArgs)

Handles ExitToolStripMenuItem.Click
        'Closing the application
End Class

The output window is look like the image below: 



I hope this article help you to understand about MDI Applications in Visual Basic .NET.


More Articles

© 2020 DotNetHeaven. All rights reserved.