ARTICLE

How to create MDI Forms in VB.NET

Posted by Rohatash Kumar Articles | Visual Basic 2010 October 15, 2010
In this article we will learn how to create MDI forms in VB.NET.
 
Reader Level:

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

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor