You are on page 1of 18

MDI Overview

This document introduces you to the concept of Multiple Document Interface (MDI) and how to
create menus within an MDI application. You will learn to create an MDI application in
Microsoft Visual Studio .NET and learn why you might want to use this type of interface. You
will learn about child forms that are contained within the MDI application, and learn to create
shortcut, or context-sensitive, menus.

MDI is a popular interface because it allows you to have multiple documents (or forms) open in
one application. Examples of MDI applications include Microsoft Word, Microsoft Excel,
Microsoft PowerPoint®, and even the Visual Studio integrated development environment itself.
Each application consists of one (or more) parent windows, each containing an MDI client area
—the area where the child forms (or documents) will be displayed. Code you write displays as
many instances of each of the child forms that you want displayed, and each child form can only
be displayed within the confines of the parent window—this means you can't drag the child
forms outside the MDI container. Figure 1 shows a basic MDI application in use.

Figure 1. Use MDI to open multiple windows and have them all contained within the
parent area

Single Document Interface

Don't be misled: MDI is only one of several possible paradigms for creating a user interface. You
can also create applications that display just a single form. They're easier to create, in fact. Those
applications are called Single Document Interface (SDI) applications. Microsoft Windows®
Notepad is an SDI application, and you can only open a single document at a time. (If you want
multiple documents open, you simply run Notepad multiple times.) You are under no obligation
to create your applications using the MDI paradigm. Even if you have multiple forms in your
project, you can simply have each one as a stand-alone form, not contained by any parent form.

In Visual Basic 6. any menus.Uses of MDI You'll use MDI most often in applications where the user might like to have multiple forms or documents open concurrently.NET. MDI is also handy when you have a large application. you can turn any form into an MDI parent form by simply modifying a property. and project manager applications (like Microsoft Project) are all good candidates for MDI applications. This size is based on the size of the MDI parent's client area. • Child forms can be moved and sized only within the MDI parent's client area. and you want to provide a simple mechanism for closing all the child forms when the user exits the application. and you can have as many MDI parent forms as you require within the same project. they don't actually become real Form objects until you instantiate them at run time. Creating an MDI Parent Form To create an MDI parent form. spreadsheet applications (like Microsoft Excel). In Visual Studio . . Word processing applications (like Microsoft Word). and you had to use the Project menu to add that one special form. and any tool bars. the MDI parent form and the MDI child forms take on special features: • All child forms are displayed within the MDI parent's client area. You may have as many different child forms (the forms that remain contained within the parent form) as you want in your project. That is. Note The user interface objects you've designed within the Visual Studio environment are really templates for forms. Tip Note the difference here between Visual Studio . • Child forms can be maximized within the parent's client area and the caption of the child form is appended to the caption of the MDI form. Therefore. you could only have a single MDI parent form per application.0 behavior. This form will now be able to contain other forms as child forms.0. You can instantiate and then show as many instances of as many different templates as you need. You can override this by setting the FormBorderStyle property of the child form to any of the fixed type of borders. You may have one or many container forms within your application. your project can contain as many different templates for MDI child forms as you like. • Child forms can be minimized and their icon will be displayed within the parent's client area. you can simply take one of your existing forms and set its IsMDIContainer property to True. The client area is the area below the MDI parent's title bar. • Windows automatically gives child forms that have their FormBorderStyle property set to a sizable border a default size. A child form is nothing more than a regular form for which you dynamically set the MdiParent property to refer to the MDI container form. while your applications are running.NET and Microsoft Visual Basic® 6. Run-time Features of MDI Child Forms At run time.

6.NET 2. They're out of the way. . Open Visual Studio . and arranging windows. Double-click the MainMenu tool in the Toolbox window to add a new object named MainMenu1 to the form tray. set the form's IsMdiContainer property to True.NET. Note Unlike the form designer in Visual Basic 6. 3. all of the loaded children will also be unloaded. • Child forms cannot be displayed modally. you will walk through the steps of creating a simple MDI application using Visual Studio . Note The client area includes any usable area on the MDI form minus any toolbars or status bars that you may have added to the MDI form. With the frmMain selected. Set the name of the project to MDI. 5. That's all there is to it: you've created an MDI parent form. Rename the form that is created automatically to frmMain. • The MDI form can be minimized and only one icon will be displayed on the desktop representing the MDI form and all of its children. Create a new Windows application project.sln. the Visual Studio . Set the WindowState property to Maximized. Create the MDI Parent Form To create the MDI parent form 1. Visual Studio . 4. you will create a new form that will be the MDI parent form.0.NET includes a new menu designer that makes creating and modifying menus a snap. • If the MDI form is unloaded. To add menus to your MDI parent form 1. At the top of the MDI parent form. Create an MDI Project In this section. click the box with Type Here in it and type &File. To do this. and then you will load the product form from a menu as a child form. Creating Menus Your main form will require menus so that you can perform actions such as opening child forms.vb. This is a real improvement! 2.NET form designer places controls that don't have a user interface at run time into a special area on the form designer: the form "tray". copying and pasting data. and don't get buried underneath other controls. You will add some menus to this new form.

check the Effects page: the Hide keyboard navigation indicators until I use the Alt key option controls this behavior. In the Display Properties dialog box. Press Enter to move to the next menu item and type a hyphen (-). you'll see another small box with the text.0. You should have something that looks like Figure 2. Pressing Alt+<the letter> acts as a hotkey. You have now created the first drop-down menu on your main form.NET will insert a separator above the current item for you. Press Enter and type E&xit. • &Edit • Cu&t • &Copy • &Paste Once more to the right of the Edit menu and at the same level. activating the menu item. Tip Rather than using the "-" to indicate a divider in the menu. Select "Insert Separator" from the context menu. it's possible that the hotkeys won't show up underlined until you press the Alt key. • &Window • &Cascade . inserting an ampersand (&) into a menu caption displays the caption with an underscore under the following letter. 3. This setting is buried in the Display applet within Control Panel. One thing to note: if you're using Windows 2000 or later. 5. Press Enter to move to the next menu item and type &Products. Figure 2. Click it and type the following menu items by pressing Enter after each one. 4. Type Here. Tip Just as in Visual Basic 6. and Visual Studio . in this case). The menu designer allows you to type your menu structure in a WYSIWYG fashion To the right of the File menu and at the same level. you can insert the next menu item (Exit. add the following menu items in the same manner. and then right-click the new item.

Visual Studio . and on the File menu.) Instead of clicking each menu item one at a time and then moving over to the Properties window to set the Name property. make sure the main form is open in Design view. you'll need to set the Name property for each. Display a Child Form To add the code that displays the child form. frmProducts. • Tile &Horizontal • Tile &Vertical • &Arrange Icons Creating Names for Each Menu After creating all the menu items.MdiParent = Me . double-click Products. Use the following names for your menu items: • mnuFile • mnuFProducts • mnuFExit • mnuEdit • mnuECut • mnuECopy • mnuEPaste • mnuWindow • mnuWCasade • mnuWHorizontal • mnuWVertical • mnuWArrange Test out your application: Press F5 and you should see your main MDI window appear with your menu system in place. then select Edit Names from the context menu. Modify the procedure so that it looks like the following: Private Sub mnuFProducts_Click( _ ByVal sender As System.Click Dim frm As New frmProducts() frm. Visual Studio provides a shortcut: Right-click an item in the menu. it's important to choose a name you can understand from within your code. This is certainly quicker than using the Properties window to accomplish the same task.NET will create the stub of the menu item's Click event handler for you.EventArgs) Handles mnuFProducts.Object. (Because you'll refer to the name of each menu item from any code you write concerning that menu item. Now you can simply click each menu item and set the name property directly on each menu. _ ByVal e As System.

Then. ' Increment the caption counter. Finally. Static intCount As Integer 8. which refers to a new instance of the frmProducts form in the sample project. the form will simply load as a new normal form. To uniquely identify each child form 1. • If you don't call the Show method. that's the MDI parent form.MdiParent = Me . indicating that its parent should be the current form (using the Me keyword). One alternative is to modify the caption of the window as you load each instance. Private Sub mnuFProducts_Click( _ 3. Dim frm As frmProducts 7. outside the MDI parent. whose menu item you just clicked. you set the MdiParent property of the new form. you can create a static variable to contain a counter. Differentiating Between Child Windows You'll note that each instance of the Products form looks identical.Click 6. intCount += 1 13. ' Set the caption to be unique. you can set the MDI parent to be a different MDI container if you like. frm.EventArgs) _ 5. frm = New frmProducts() 10. You'll most likely need some way to differentiate the windows. frm. and then assign that value into the Text property of the form. making it appear on the screen. this keyword refers to the class whose code is currently running. 15. _ 4.ToString() 16. 14.NET—just as in Visual Basic 6. 17. the code calls the Show method of the child form. Modify the mnuFProducts_Click procedure so that it looks like this: 2. 12.0. • You don't have to set the MdiParent property of the new child form. the child form won't ever display. Handles mnuFProducts. frm. 9.Text = frm. ByVal sender As System. If you don't. In this case. As a matter of fact. 11.Text & " " & intCount. ByVal e As System. increment that variable each time you open a form. frm. Some interesting things to note: • Me is a built-in keyword in Visual Basic . In the sample.Object.Show() End Sub This code declares a variable.

frm. The default value for this property is 0. however. Table 1. indicating that this menu item will be added at the end of the existing menu items. Run the project. create a few Products forms. The MergeType property allows you to specify what happens when menu items merge Value Description Add The MenuItem is added to the collection of existing MenuItem objects in a merged menu. the menu will be added at the end of the main menu. to declare a variable inside a procedure creates a variable that maintains its value from one invocation of the procedure to the next. in this case—you want intCount to maintain its value. using the MergeOrder and MergeType properties of the individual menu items. The MergeOrder property controls the relative position of the menu item when its menu structure gets merged with the parent form's menus. that variable gets reinitialized each time the procedure is called. The MergeType property controls how the menu item behaves when it has the same merge order as another menu item being merged. By default. This means that if you create a child form with a menu on it. In Visual Studio . That's what you want. Remove The MenuItem is not included in a merged menu. Replace The MenuItem replaces an existing MenuItem at the same position in a merged menu. the variable maintains its value. a menu item's MergeOrder property is set to 0. End Sub 20. which shows a child form called from the parent form's main menu. The MergeType property is set to Add by default. All of the items on the parent's main menu have their MergeOrder properties set to 0 and . you can control how the menus interact. Note What's that Static keyword? Using Static. This form has a Maintenance menu on it (and the parent form does not). rather than Dim. Child Menus in MDI Applications What if a child form has its own set of menus? How do those menus interact with the menus of the parent form? In previous versions of Visual Basic you really didn't have much control over the behavior—the menus of the currently active child simply replaced the menus of its parent. so that it continues to increment each time you create a new instance of frmProducts.NET. 18. (Default) MergeItems All submenu items of this MenuItem are merged with those of existing MenuItem objects at the same position in a merged menu. When you declare a variable using Dim. Consider Figure 3. When you use Static.Show() 19. and note that the caption of each form includes a different number. Table 1 shows a list of the possible values you can assign to the MergeType property.

. 3. 5.this menu's MergeOrder property is set to 0. A child form that has menus will by default be added to the end of the main menu To create the form in Figure 3 1. click Add Windows Form. Add a MainMenu control to this form. Set the new form's name to frmChildWithMenus. On the Project menu.vb. You can see that by default. so this menu will be added at the end of the main menu on the MDI parent form. the menu is added to the end of this form. 2. Windows Form menus Menu Name &Maintenance mnuMaint &Suppliers mnuMSuppliers &Categories mnuMCategories If you were to call this form exactly like you did the Products form in the previous section you will see that your main form looks like Figure 4. Add the following menus as shown in Table 2. Figure 3. 4. Table 2. Set the Name property for the MainMenu control to mnuMainMaint.

Double click this new menu item and modify its Click event handler so that it looks like this: 6. Working with MDI Child Forms . you could set the MergeOrder property on the Edit menu item to 1. Menus are added to the end of the main menu by default Call this form by adding a new menu item under the File menu: 1. 2. Handles mnuFChildMenus. and the MergeOrder property on the Window menu to a 2. Private Sub mnuFChildMenus_Click( _ 7. 5. frm. _ 8. but before the Window menu). Open frmMain. End Sub Note If you wish to merge the Maintenance menu in between the Edit and Window menus. Then on the Maintenance menu item on frmChildWithMenus.Click 10.Show() 13. set the MergeOrder property to 1 and leave the MergeType with its default value. Taking these steps will add the Maintenance menu after the menu on the main form with the same MergeOrder number as it has (that is. after the Edit menu. Click on the separator after the Products menu item and press the Insert key to add a new menu item.Figure 4.EventArgs) _ 9. Add.vb in Design view. Dim frm As New frmChildWithMenus() 11. Type Child form with Menus as the text of this new menu item. Set the Name property of this new menu item to mnuFChild.Object. 3.MdiParent = Me 12. ByVal sender As System. 4. ByVal e As System. frm.

Enabled = _ . Modify the Select event handler. Handles mnuWCascade. _ 6. attempting to work with the ActiveMdiChild property of the parent form will trigger a run-time error. choosing options under the Window menu. Tip The LayoutMDI method replaces the Arrange method you may have used in Visual Basic 6. Select mnuWindow from the Class Name combo box (the list on the top left of the editor window). What If There's No Active Child Form? If there's no active child form. For the Cascade menu item. Me. 3. modify the Click event handler so that it looks like the following: 4. double-click Cascade. ByVal e As System. End Sub On the Window menu. To add this feature. you can check the value of the property in the Click event handler for the Window menu item. press F7 to edit the form's code module.LayoutMdi(MdiLayout. On the Window menu. To avoid this situation. 2.Cascade) 9. double-click each menu item and add the appropriate code. 3. Table 3. Private Sub mnuWCascade_Click( _ 5.TileHorizontal Tile Vertical MdiLayout.Object. much as you can do in Word or Excel.EventArgs) _ 7. Private Sub mnuWindow_Popup( _ 5. _ 6. ByVal e As System. Choose one of these values when arranging child windows Menu Item Enumerated Value Tile Horizontal MdlLayout.If you have multiple child forms open. mnuWCenterChild.EventArgs) _ 7.Click 8. you may want to have them arrange themselves. follow these steps: 1.TileVertical Cascade MdiLayout. and enable or disable the Center Child Form menu item accordingly.ArrangeIcons Add some menus to your main form for each of these options: 1. ByVal sender As Object.vb in Design view. Table 3 lists the available options when arranging child windows.Cascade Arrange Icons MdiLayout. ByVal sender As System.Popup 8. Handles mnuWindow. so that it looks like this: 4. With frmMain open in Design view. Open frmMain. and then select Select from the Method Name combo box (the list on the right).0. 2.

and verify that if you have child windows displayed. Not (Me. 3. End Sub 11. 2. you'll enable the menu item. and it's easy to create a window list menu to manage the child windows. just like the MainMenu control did). and then click the Window drop-down menu. verify that the menu item is disabled. you can edit the menu items to be displayed by this context menu. The whole line of code assigns the return value from the expression in parentheses to the Enabled property of the menu item. If you wish to see a list of all of the child forms and be able to give a specific child form focus. menu. If it's True. if it's not true that the ActiveChild is Nothing. set the MdiList to True. Load frmMain in Design view. the Center Child Form menu item is enabled. making it just as easy to create context menus as it was to create main menus. ActiveChild. The value in parentheses (Me. You should see each instance of the Product form that you opened displayed in the window list. In this case. and you must use the Is operator to check for this. 9. follow these steps: 1. . How does this work? Here are some things to consider: • The Popup event occurs when you select a menu item that includes sub-items. you can click the right mouse button and see a context- sensitive. In this case. In the Properties window. If there isn't a child form open. Nothing) returns a Boolean value: it's either True or False. since that event doesn't occur for menu items that contain sub-items. 4.Run the project. These menus give you the ability to perform actions based on the current context—that is. Select frmMain's Window menu. or shortcut (pop-up). Run the project.) • The Is operator allows you to compare values to the built-in value Nothing. The Not operator toggles the returned value to be the opposite Boolean value. Once you've dropped one of these controls on your form (it will appear in the tray area. Visual Studio provides the ContextMenu control. (The = operator checks values for equality: the Is operator checks references to objects for equality.) • The syntax of the procedure may be confusing. changing depending on the current situation.NET will keep track of all child forms that you create.ActiveMdiChild Is Nothing) 10. Tracking Child Windows Visual Basic . open a couple of Products forms. Creating Shortcut Menus In most modern Windows applications. (You can't use the Click event. the ActiveMdiChild property returns this special value if it doesn't refer to a form. 4. Is. you'll disable the menu item.

2. you start with the first menu item under the top-level menu. 4. Open frmProducts in Design view. Click the ContextMenu control to give it focus. In the Toolbox. . 8. Double-click this control to add it to the tray area of the form. 3. 6. Add the menu items (shown in Table 4) to this control. create a top-level item that won't ever be displayed as the parent for your items 7. In the Properties window. find the ContextMenu control. To add a context menu to the Products form: 1. set the ContextMenu property to the ContextMenu control you just created. and righ-click on the Product ID text box to see the context menu appear. Context menu items Menu Name &Lookup mnuPLookUp &Copy mnuPCopy &Paste mnuPPaste Figure 5. 5. 9. Click the Product ID text box. When adding items to the ContextMenu control. This makes it possible for one form to contain both MainMenu and ContextMenu controls. Tip You can place as many ContextMenu controls as you need on your forms. and set the Name properties as shown. Change the Name property to cmnuProdID. click Products to create a child form. When you add to a context menu. On the File menu. Table 4. Figure 5 shows the finished context menu.Note The design of your context menu won't display on the form until you've clicked the ContextMenu control. Run the project. cmnuProdID.

Private Sub mnuFRemoveMenus_Click( _ 13. Private Sub mnuFAddMenus_Click( _ 4.Checked = True 9. In this section. and add and remove menu items programmatically. End Sub 11. ByVal e As System. you could now add code to respond to the Click events on each of these menus.Object. Add three menu items. double-click Remove Menus and modify its Click event procedure so that it looks like this: 12. 2.If you were completing this form.Object.EventArgs) _ . on the File menu. so that it looks like this: 3.vb in Design view. ByVal sender As System. Table 5. For example. as described in Table 5. File menu items Menu Name &Add Menus mnuFAddMenus &Remove Menus mnuFRemoveMenus &Add &New Menu mnuFAddNew Checking and Unchecking Menu Items Visually selecting a menu item programmatically is easy: simply set the menu item's Checked property to True or False. Manipulating Menus at Run Time You may need to modify the behavior of menu items while your application is running. On the File menu. End If 10. If Not mnuFAddMenus. _ 5. 2. add and remove the check by following these steps: 1. double-click Add Menus to view the Click event procedure. you might want to indicate that you've added new menu items by adding a check to the Add Menus item.Checked Then 8. Modify the event procedure. and remove it once you've removed the items. you'll see how to check and uncheck. but for now. You'll add and remove the menu items in the next section. ByVal sender As System. 1. ByVal e As System. 3. To repeat the previous two steps. you will need to add three new menu items under the File menu on your MDI form. as necessary. Open frmMain. Handles mnuFAddMenus. mnuFAddMenus. _ 14. To set up for the following sections. Click the File menu to display its sub-items.EventArgs) _ 6.Click 7.

you couldn't delete static menu items. If a menu item contains other menu items (as each top-level menu item does).Checked Then 17. Handles mnuFAddMenus. To do this. click Remove Menus to verify that the check has been removed. End If 19. you might want to add two new menu items on the File menu.Add("New Menu 1") 12. ' Adds these menus to the end of the File menu 10.NET.Checked Then 8. mnuFAddMenus.0.Click 16. Handles mnuFRemoveMenus. at run time. In Visual Studio . Using the Add and Remove (or RemoveAt) methods of the MenuItems collection. If mnuFAddMenus. double-click Add Menus. End Sub Each menu item contained within the MainMenu (or ContextMenu) control is itself a MenuItem object. 15.Click 7. . and just as with any other object. double-click Add Menus to view its Click event handler. you can delete any menu item. To repeat. Adding and Removing Menus Windows Forms allows you to add and remove menus programmatically at run time. In this case. End With 14. Run the project. 2. End Sub 20.Object. on the File menu. End If 15.Checked = True 9.MenuItems 11. you can use its MenuItems property to refer to the collection of menu items it contains. On the on the File menu. ByVal sender As System.Checked = False 18. _ 5. With mnuFile. Adding Menus Programmatically To add a menu item. you could only delete menu items that you created dynamically. Verify that you see a check next to the item. ByVal e As System.Add("New Menu 2") 13. For example. and on the File menu.EventArgs) _ 6. call the Add method of a particular menu item. you can create new menus at run time. If Not mnuFAddMenus. you called the Add method of a MenuItem object (mnuFile) to add menu . mnuFAddMenus. follow these steps: 1. you refer to the menu items using the Name property you assigned to each. . Modify the event procedure so that it looks like this: 3. Note In Visual Basic 6. and delete any menu items. That is. Private Sub mnuFAddMenus_Click( _ 4.

you're indicating the state of that menu item—it's either selected.items to the collection of items. you can either call the MenuItem collection's Remove or RemoveAt method. or it's not. mnuFile was the name you assigned to the File menu item.NET doesn't provide a way to make this happen for you. Although Visual Studio . modify the Click event procedure for the Remove Menus items on the File menu.1) End With mnuFAddMenus.Object.1) . (In this example. you need to take that into account when removing menu items. selecting one item from the group forces all the other items in the group to be deselected. it does supply the RadioCheck property of menu items that at least provides a visual indication. Normal checked menus work individually.RemoveAt(. menu items with their RadioCheck property set to True display a dot when they're .Count .Checked = False End If End Sub Run the project to verify that choosing the Add and Remove Menus menu items correctly adds and removes the two extra items. Remove requires you to provide a MenuItem object. _ ByVal e As System.Checked Then With mnuFile. if you instead want to remove items by their position within the menu.Click If mnuFAddMenus. and are independent of other menu items. To handle removing the two menu items you've just added. Because menu items are numbered starting at 0 (as are all collections and arrays in Visual Basic . In this example.RemoveAt(.EventArgs) _ Handles mnuFRemoveMenus. Rather than seeing a normal check.Count . You may have a need to treat a group of menu items as a dependent set.) Removing Menus Programmatically To remove menu items programmatically.MenuItems ' Remove the last two items . the simplest way to remove the menu items you created in the previous steps is to specify their position within the menu. so that the procedure looks like this: Private Sub mnuFRemoveMenus_Click( _ ByVal sender As System.NET). You'll call the RemoveAt method to do the work. Using Menu Groups When you add a check to a menu item. In this case. call the RemoveAt method.

selected. mnuWVertical. click Insert Separator. 2. End Sub 17. follow these steps: 1.Checked = False 13. _ 10. selecting all four. With frmMain open in Design view. Add the following procedure to the frmMain class: 6. select the Window>Center Child Form menu item.Click. Run the project. modify properties and add code so that the four window management menu items (Cascade. Tile Vertical. set the RadioCheck property for the four selected menu items to True. It's still up to your code to deselect all the other items in your menu group. Right-click. and use the Window menu items to arrange the children. ByVal e As System. Handles mnuWArrange. mnuWArrange. 4.Click. mnuWVertical. Arrange Icons) work as a group. Tile Horizontal.Checked = False 12. Tile Horizontal. then at the same time. 3.Checked = True 16. To demonstrate this behavior. To do that. In the Properties window. MenuItem). Private Sub RadioCheck_Click( _ 7. As you use the Cascade. _ 8. and on the shortcut menu. CType(sender.Click 11.EventArgs) _ 9.Object. which inserts a separator item above the selected item. and other menu items. Click on the Window>Cascade menu item. mnuWHorizontal. Figure 6 shows the results of adding this new feature. ByVal sender As System. mnuWHorizontal. once the user selects a menu item.Checked = False 14.Click. press Ctrl and click the other four window management items on the menu. mnuWCascade. create some Product forms. mnuWCascade. . 5.Checked = False 15. you should see a circle next to the most recently selected item.

you're handling the Click event of four different menu items.Object. you provided a new procedure (RadioCheck_Click) that handles Click events for each of the four menu items you want to have work together. • Within the procedure. To convert the Object variable into a MenuItem .) • You must add a Handles clause for each event you want to handle.NET—you can hook up as many event handlers to a specific event as you need. you can use the first parameter (named sender. (It must be a Sub. Setting a menu item's RadioCheck property to True shows a dot. in this example) to figure out which object triggered the event. In this case. That is. and then checks the item that triggered the event. This example first sets each of the four items to be unchecked. Figure 6. using the Handles clause on a procedure. it must receive two parameters (one as System.EventArgs) and return nothing at all. Here are the important issues: • The procedure you want to call must match the procedure signature of the standard Click event for menu items. the other as System. Here. It's also interesting to note how the RadioCheck_Click procedure set the RadioCheck property of the object it received as its first parameter. This example took advantage of a new feature in Visual Basic . next to selected items How Did the Code Work? It may seem odd that you managed to add new functionality to four menu items without modifying their event procedures at all. in other words. rather than a check.

the AddHandler statement. and if you don't care about the order in which the procedures handle the event (in this case. indicating the variable to convert. . MenuItem).NET. the code calls the CType function. Because Visual Basic .type. which gives you more control. You also learned to create and manipulate menus.0). you don't). it's an easier way to add extra functionality. Visual Basic .Checked = True You'll use CType a lot in Visual Basic . you cannot control the order in which those events get handled. Summary In this document you have learned to build an MDI application using several techniques that you find in professional Windows applications. This important function allows you to convert variables from one type to another. Whether or not you choose to use the MDI paradigm will depend on the complexity of your application and how many forms will need to be displayed at one time. and the result type (MenuItem): CType(sender. however. Using the Handles clause is simpler.NET does supply a different mechanism.NET is so strictly typed (it's always careful about the specific data types you're working with. unlike Visual Basic 6. Note It's important to note that when you use the Handles clause as you did here to add event handlers. you'll often need to use this function to convert variables into a specific data type.