Results 1 to 3 of 3

Thread: how to work with menus

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2000
    Location
    Belgium
    Posts
    42

    Question

    Hi,

    can anyone tell/show me how you can 'build' menus dynamically using code and not the 'menu-editor'?

    Thanx

    B.

  2. #2
    Addicted Member
    Join Date
    Feb 2000
    Location
    CWMBRAN,WALES,UK
    Posts
    146
    Hi,
    I'm not sure if this is what you are after, but the following code will generate menu items at runtime
    Code:
    Option Explicit
    
    Private NextMenuIndex As Integer
    
    ' Create a new menu item.
    Private Sub cmdMakeItem_Click()
        ' If this is not the first item, load the
        ' new item. Otherwise use the item we created
        ' at design time.
        If NextMenuIndex > 0 Then _
            Load mnuCommandsSub(NextMenuIndex)
    
        ' Set the item's caption.
        mnuCommandsSub(NextMenuIndex).Caption = _
            "Command &" & Format$(NextMenuIndex)
    
        ' If this is the first item, enable the menu.
        If NextMenuIndex = 0 Then mnuCommands.Enabled = True
    
        ' Set NextMenuIndex to the index of the next item.
        NextMenuIndex = NextMenuIndex + 1
    End Sub
    ' Remove a menu item.
    Private Sub cmdRemoveItem_Click()
        ' If this is the first item, disable the menu
        ' (we cannot unload a control created at design time).
        NextMenuIndex = NextMenuIndex - 1
        If NextMenuIndex = 0 Then
            mnuCommands.Enabled = False
        Else
            ' Unload the last item.
            Unload mnuCommandsSub(NextMenuIndex)
        End If
    End Sub
    
    ' Respond to a dynamically created menu command.
    Private Sub mnuCommandsSub_Click(Index As Integer)
        MsgBox "Execute command number " & Format$(Index)
    End Sub
    
    ' Unload the form.
    Private Sub mnuFileExit_Click()
        Unload Me
    End Sub
    Hope thats some use to you
    GRAHAM

    [Edited by GRAHAM on 12-30-2000 at 10:53 AM]

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2000
    Location
    Belgium
    Posts
    42
    Hey Graham,

    Thanx for the info, can you give me a bit more info?

    Is it so that I already have to create the 'menu-headers' I mean the toplevel of the 'menu-bar'?

    And is it possible to make 'sub-menus'?
    ex. Format
    Align
    Rights
    Lefts
    Make same size
    Widths
    Heights
    Or where can I find more info and/or examples?

    Thanx a lot for the help.

    B.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width