How to create MDI Forms in VB.NET

In this article we will learn how to create MDI forms in VB.NET.
  • 27070

In this article we will learn how to create MDI forms in VB.NET.

MDI (Multiple Document Interface)

An application allows to work on multiple files and where the user needs to work with several documents at one time.Such applications contain a parent form as container form and other child forms.

  1. To make a form as MDI Form set its IsMdiContainer property as true.
  2. To define a parent form to a child form set MdiParent property.        
  3. To arrange the child forms, use LayoutMdi() method.       
  4. To get reference of the current child form use ActiveMdiChild property.         
  5. To get reference of a control from the child form use its Controls collection.

Now, double click on the menustrip and colordialog control and create a menu in the form. the form look like this the below forms.

mdi2.gif

Figure 1.

Format menu look like this the below form.

mdi3.gif
 

Figure 2.

Window menu show look like this the below form.

mdi4.gif

figure 3.
 

Now run the form and click on the new to create new form like this the below form.

mdi.gif

Figure 4.
 

Now add this code.

Namespace MDIApp

    Partial Public Class frmMDI

        Inherits Form

        Private i As Integer

        Public Sub New()

            InitializeComponent()

        End Sub

 

        Private Sub frmMDI_Load(ByVal sender As Object, ByVal e As EventArgs)

            Dim f As New frmChild()

            f.MdiParent = Me

            f.Show()

            i = 2

        End Sub

 

        Private Sub newToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)

            Dim f As New frmChild()

            f.MdiParent = Me

            f.Text = "Documnent" & System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)

            f.Show()

        End Sub

 

        Private Sub cascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)

            Me.LayoutMdi(MdiLayout.Cascade)

        End Sub

 

        Private Sub tileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)

            Me.LayoutMdi(MdiLayout.TileHorizontal)

        End Sub

 

        Private Sub tileVerticalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)

            Me.LayoutMdi(MdiLayout.TileVertical)

        End Sub

 

        Private Sub arrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)

            Me.LayoutMdi(MdiLayout.ArrangeIcons)

        End Sub

 

        Private Sub colorToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)

            colorDialog1.ShowDialog()

            Dim t As RichTextBox = DirectCast(Me.ActiveMdiChild.Controls("txtMain"), RichTextBox)

            t.SelectionColor = colorDialog1.Color

        End Sub

  End Class

End Namespace

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.