Visual Basic Reference

WindowList Property Example

This example creates some menu commands, illustrates the WindowList menu functionality, and shows how to enable your users to add new forms to a multiple-document interface (MDI) application. To try this example, create an MDIForm object with the Add MDI Form command on the Project menu. On Form1, set the MDIChild property to True, and create a menu named File. Select the WindowList box for the File menu. On your File menu, create a New command, set its Name property to FileMenu, and set its Index property to 0 to create a control array. Paste the code into the Declarations section of the form, and then press F5 to run the program. Choosing the New command on the File menu creates new MDI child forms. Their names are listed at the bottom of the File menu.

  Private Sub Form_Load ()
   FileMenu(0).Caption = "&New"   ' Set access key in caption.
   Load FileMenu(1)   ' Create new menu item.
   FileMenu(1).Caption = "-"   ' Set separator.
   Load FileMenu(2)   ' Create new menu item.
   FileMenu(2).Caption = "E&xit"   ' Set caption and access key.
End Sub

Private Sub FileMenu_Click (Index As Integer)
   Select Case Index
      Case 0   ' Select New command.
         Dim NewForm As New Form1   ' Create a duplicate of Form1.
         ' Load NewForm and set a unique caption.
         NewForm.Caption = "Untitled" & Forms.Count
      Case 2   ' Select Exit command.
         End   ' End the program.
   End Select
End Sub