Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Copying Menus Between Projects

Here's a tip that you should file away for the day when you want to copy a menu from one form to another project's form file. Although several methods exist, one way that you can accomplish this copy is to perform these steps:

  1. Make a backup of the target form where you want to copy the menu.
  2. Start the Windows Notepad Editor.
  3. Load the form with the menu into the editor. Visual Basic saves form files in a text format that you can load into an editor.
  4. Copy all the text that describes that form's menu to the Windows Clipboard. Here is a form's text that describes the previous section's menu:
    Begin VB.Menu mnuFile
       Caption         =   "&File"
       Begin VB.Menu mnuFileNew
          Caption         =   "&New"
       End
       Begin VB.Menu mnuFileOpen
          Caption         =   "&Open"
          Begin VB.Menu mnuFileOpenBinary
             Caption         =   "&Binary"
          End
          Begin VB.Menu mnuFileOpenText
             Caption         =   "&Text"
          End
       End
       Begin VB.Menu mnuFileClose
          Caption         =   "&Close"
       End
       Begin VB.Menu mnuFileBar1
          Caption         =   "-"
       End
       Begin VB.Menu mnuFileExit
          Caption         =   "E&xit"
       End
    End
    Begin VB.Menu mnuEdit
       Caption         =   "&Edit"
    End
    Begin VB.Menu mnuView
       Caption         =   "&View"
       Begin VB.Menu mnuViewHighlighted
          Caption         =   "Highlighted"
          Checked         =   -1  'True
       End
    End
    Begin VB.Menu mnuHelp
       Caption         =   "&Help"
    End
    
  5. Open the target application's form file. Each Begin...End block defines an object on the form. Locate an End statement that completes an object's definition and paste the Clipboard's form description there. When you save the file and load the form, the menu will be working as it does in the other. You now can write the event procedures for the menu options.

Share ThisShare This

Informit Network