Freigeben über


Visual Basic Concepts

Adding a Menu to the ActXDoc Project

You can add menus to your ActiveX document using the Menu Editor. Because an ActiveX document alone cannot have a menu, the menu you create will be merged with the application you used to view the ActiveX document. Thus, you must consider menu negotiation when adding a menu to an ActiveX document.

When users navigate to your ActiveX document, they may not have any indication of its origin (or that it is an ActiveX document). To remedy this, you should always include an "About" form with your ActiveX document.

Note   This topic is part of a series that walks you through creating a sample ActiveX control. It begins with the topic Creating an ActiveX Document.

To add a menu and About box to the FirstDoc ActiveX document

  1. On the Project menu, click Add Form.

  2. In the Add Form dialog box, double-click the About Dialog icon to add an About Box form to the project.

  3. Set Caption property of the form and controls according to the following table.

Object Caption value
frmAbout About FirstDoc
lblTitle FirstDoc ActiveX Document
lblVersion Version 1.0
lblDescription ActiveX document
  1. Delete the Label control named lblDisclaimer.

  2. In the Project Explorer window, double-click FirstDoc to bring its designer forward.

  3. Click the FirstDoc designer to select it, and on the Tools menu, click Menu Editor to display the menu editor dialog box.

  4. Click the Caption box and type &Help.

  5. Click the Name box and type mnuHelp.

  6. Click the NegotiatePosition box, and click Right.

  7. Click the Next button to create a new menu item.

  8. In the Caption box type About FirstDoc.

  9. In the Name box type mnuAbout.

  10. Click the right-facing arrow button to indent the menu item.

  11. Click OK.

  12. Double-click the FirstDoc designer to bring its Code window to the front.

  13. Add the following code to the mnuAbout Click event:

    Private Sub mnuAbout_Click()
       frmAbout.Show vbModal
    End Sub
    

Running the Project

Once you have added a menu to the UserDocument, you can run the project, view the ActiveX document in Internet Explorer, and see the how the menu has been negotiated.

  1. Run the project by pressing F5.

  2. In Internet Explorer, type the path of the FirstDoc.vbd file in the Address box or select it from the drop-down list of previously typed addresses.

  3. On Internet Explorer's command bar, click the Help menu, and among the menu items will be the FirstDoc Help menu item.

  4. Click About FirstDoc to see the new About box.

Step by Step

This topic is part of a series that walks you through creating a sample ActiveX document.

To See
Go to the next step Life Cycle of a UserDocument
Start from the beginning Creating an ActiveX Document