Hi,
I want to create MDI form in VB.NET through code!
Please help me!
Printable View
Hi,
I want to create MDI form in VB.NET through code!
Please help me!
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.
For further information on MDI forms!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
To make the MDI container form, make a form and set its IsMdiContainer property to True.
To make a menu list the MDI child forms, set its MdiList property to True.
Use code similar to the following to add a MDI child form to the MDI container.
Code:Dim frm2 As New Form2
frm2.MdiParent = Me
frm2.Text = "Child " & Me.MdiChildren.GetLength(0)
frm2.Show()
I this this will also help you in further changes for your MDI form & creating Child forms
Creates an MDI application which consists of a main "parent" form and a child form.
Code:Imports System
Imports System.Windows.Forms
Public Module AppModule
Public Sub Main()
Application.Run(New MainForm())
End Sub
End Module
Public Class MainForm
Inherits Form
Public Sub New()
' Set parent window caption.
Text = "Main Parent Window"
' Set this to be an MDI parent form.
IsMdiContainer = True
' Create a child form.
Dim myChild As New DocumentForm("My Document", Me)
myChild.Show
End Sub
End Class
Public Class DocumentForm
Inherits Form
Public Sub New(ByVal name As String, ByVal parent As Form)
' Set the child window caption.
Text = name
' Set this to be an MDI child form.
MdiParent = parent
End Sub
End Class