MDI Visual Basic 2005

Thursday 30 December 2010

The Following are the steps to create an MDI parent Form by yourself(Not from the VB.Net itself): 
   1. Open Microsoft Visual Basic 2005, Click File – New Project (Project Name MDI Parent).


  2. Open the Properties Window of Form1. Set the IsMdiContainer property to True. The Form will be designated as an MDI parent Form, as shown below: 




 3    3. After finishing the 2 step, you have already got an MDI to perform with. If you want to make your main form(MDIParent1) to become better(Beautiful), you can input some ToolBox in the form, like MenuStrip, StatusStrip, ToolStrip, etc as you wish. (Like the below Picture and also the picture image(in the toolstrip), you find it yourself).


4.      4. The main form(MDIParent1), Just a blank form without any coding. Here is the coding :
a.     We mustn’t forget to put this, Imports System.Windows.Forms, above the public Class
b.  In the Public Class MDIParent1 Until the End Class, We can fill this coding for :
1.      For NewForm(Add Child).
   Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
     ' Create a new instance of the child form.
     Dim ChildForm As New System.Windows.Forms.Form
     ' Make it a child of this MDI form before showing it.
     ChildForm.MdiParent = Me
     m_ChildFormNumber += 1
     ChildForm.Text = "Window " & m_ChildFormNumber
     ChildForm.Show()
   End Sub

2.      For OpenFile
   Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripMenuItem.Click, OpenToolStripButton.Click
     Dim OpenFileDialog As New OpenFileDialog
     OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
     OpenFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
       If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
          Dim FileName As String = OpenFileDialog.FileName
          'Fill your code here to open the file.
        End If
   End Sub

3.      For Save
    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveAsToolStripMenuItem.Click
        Dim SaveFileDialog As New SaveFileDialog
        SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        SaveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"

        If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = SaveFileDialog.FileName
            'Fill your code here to save the current contents of the form to a file.
        End If
    End Sub

4.      Exit ChildForm
    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExitToolStripMenuItem.Click
        Global.System.Windows.Forms.Application.Exit()
    End Sub

5.      Cascade ChildForm
    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CascadeToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

6.      TileVertical ChildForm
    Private Sub TileVerticleToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileVerticalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

7.      TileHorizontal ChildForm
    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileHorizontalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

8.      Arrange ChildForm
    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ArrangeIconsToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

9.      CloseAll ChildForm
    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CloseAllToolStripMenuItem.Click
        ' Close all child forms of the parent.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private m_ChildFormNumber As Integer = 0

NOTE : You Can Skip Step 2, 3, and 4. Because in Microsoft Visual Basic 2005 has already provided the MDIParent form itself which you just click add new item, then find MDIParent Form.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.