stu nicholls dot com | menu - Professional dropdown #3

Creating MDI

  1. Start a new Window Application
  2. Now to make the main form Form1 as MDI container or parent, set its IsMDIContainer property to true
  3. This alters its appearance from a white client area to a gray one
  4. Next drag a MenuStrip control from the tool box on to Form1
  5. This causes a main menu control MainMenu1, to appear in the new pane at the bottom of the form designer with the text “Type Here” in it which is shown in Fig. 1
  6. To create a File menu, type “File” in the Type Here box. When you create a new File menu, additional “Type Here” boxes appear for the next menu in the menu bar and the first item in the File menu which is shown in Fig. 2.
  7. Add a New item to the File menu; when you do, another “Type Here” box appears beneath that item and Arrange menu item in another box as shown in Fig. 3.
  8. Now double click the New item in the File menu to open the event handler for this menu item in code. Actually we want to display new form each time we click on to New. The code is given below, the code for Arrange is also given which arranges the newly created forms in different methods. In the code Cascade is selected.
  9. Public Class Form1
    Dim NumberForms As Integer = 0
    Dim forms(10) As Form2
    Dim OtherWindow As New Form2
    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
    NumberForms += 1
    forms(NumberForms) = New Form2()
    forms(NumberForms).Text = "Document" & Str(NumberForms)
    forms(NumberForms).MdiParent = Me
    forms(NumberForms).Show()
    End Sub
    Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
    Me.LayoutMdi(MdiLayout.Cascade)
    'Me.LayoutMdi(MdiLayout.TileHorizontal)
    'Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub
  10. Create a new form class by adding a new form to the project ( Project| Add Windows form)
  11. Now place the RichTextBox control onto Form2. Make sure that the rich text box’s multiline property is set to true.
  12. To make sure that the rich text box, RichTextBox1, covers the whole client area of Form2, we can dock it. That is to adhere it to the edges of the container.
  13. Now select the Dock property and set it to fill

  14. Creating MDI Child Windows in code

    Now that we have created a new form class, Form2, for our MDI child windows, we can create and display a new object of that class each time the user clicks the File|new menu item in our program
    Because we are working with a number of child windows, we will store them in an array of forms, incrementing the number of forms each time a new one is created, setting the text in its title bar to “Document1”, “Document2” and so on

  15. Run the Application. Click on to File|New a new form gets displayed. Fig 4. Thrice it is done so three new forms have been created.

  16. Arranging MDI Child Windows
  17. Now click on to File|Arrange menu item in our application to automatically arrange MDI child windows, we can use the LayoutMdi method. The forms are arranged in Cascade as we have selected that which is shown in Fig.5.
  18. Public Sub LayoutMdi(ByVal value As MdiLayout)
    This sub procedure takes one argument, value, which is one of the MdiLayout enumeration values that defines the layout of MDI child forms
    ArrangeIcons-All MDI child icons (which are displayed when you minimize an MDI child Window ) are arranged Cascade- All MDI child windows are cascaded
    TileHorizontal-All MDI child Windows are tiled horizontally
    TileVertical-All MDI child Windows are tiled vertically

    MDI<< Previous Next >>Creating Dialog Boxes


    comments powered by Disqus
Footer1