Hi,
can anyone tell/show me how you can 'build' menus dynamically using code and not the 'menu-editor'?
Thanx
B.
Printable View
Hi,
can anyone tell/show me how you can 'build' menus dynamically using code and not the 'menu-editor'?
Thanx
B.
Hi,
I'm not sure if this is what you are after, but the following code will generate menu items at runtime
Hope thats some use to youCode: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
GRAHAM ;)
[Edited by GRAHAM on 12-30-2000 at 10:53 AM]
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.