MDI (Multiple Document Interface) Application is an application in which we can view and work with several documents at once. Example of an MDI application is Microsoft Excel. Excel allows us to work with several documents at once. In contrast, SDI (Single Document Interface) applications are the applications which allows us to work with a single document at once. Example of a single document application is Microsoft Word in which only one document is visible at a time.
Open a new Windows Application in Visual Basic .NET. The application will open with a default form, Form1. Add another form, Form2 to this application by right-clicking on the project name in Solution Explorer window and selecting Add->Add Windows Form. You can add some controls to Form2. For this application we will make From1 as the MDI parent window and Form2 as MDI child window. MDI child forms are important for MDI Applications as users interact mostly through child forms. Select Form1 and in it's Properties Window under the Windows Style section, set the property IsMdiContainer to True. Setting it to true designates this form as an MDI container for the child windows. Once you set that property to true the form changes it's color. Now, from the toolbox drag a MainMenu component onto Form1. ame the top-level menu item to File with submenu items as New Child Window, Arrange Child Windows and Exit.
With this application a new child window is displayed each time the New Child Window menu item is clicked, all child windows will be arranged when you click Arrange Child Windows menu item.
Code:
Public Class Form1 Inherits System.Windows.Forms.Form
Dim childForm As Integer = 0
Dim childForms(5) As Form2
'declaring an array to store child windows
'five child windows (Form2) will be displayed
#Region " Windows Form Designer generated code "
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e _
As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles MenuItem2.Click
childForm += 1
childForms(childForm) = New Form2()
childForms(childForm).Text = "ChildForm" & Str(childForm)
'setting title for child windows and incrementing the number with an array
childForms(childForm).MdiParent = Me
childForms(childForm).Show()
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles MenuItem3.Click
Me.LayoutMdi(MdiLayout.Cascade)
'arranging child windows on the parent form with predefined LayoutMdi method
'Different layouts available are, ArrangeIcons, Cascade, TileHorizontal, TileVertical
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal_
e As System.EventArgs) Handles MenuItem4.Click
Me.Close()
'closing the application
End Sub
End Class
For further information on MDI forms!
Bookmarks