Figure 13.1.1.1: Tree structure in a menu list
The 'Tools' menu, for example, contains the three menus: Options, Color palettes and the Preview (Optional) menu, with the Color palettes menu containing two menus in the menu list, as shown in Figure 13.1.1.1.1:
Please note that in this example, the two menus Extras and Colour palettes only fulfil the role as containers for further menus, because they only display the other menus in the assigned menu list after one click, but do not trigger any program actions! In addition, the terms menu, menu bar, menu list and submenu are used as described in the first part.
There are 3 proven variants of how to create menus in a self-defined structure using source code at runtime. This can be done quickly and easily if you have already noted the tree structure of the future menu in full beforehand.
Here is an approach, where only one menu list for the 'Extras' menu from the above mentioned project (→ Figure 13.1.1.1) is described:
... Private mnuMenu2 As Menu Private mnu21Optionen As Menu Private mnu22SelectColor As Menu Private mnu23PreView As Menu Private mnu221Palette1 As Menu Private mnu222Palette2 As Menu ... Private mnuSpace As Menu Public Sub Form_Menu() mnuMenu2 = New Menu(FMain, False) ' 2. Entry in the menu bar, visible mnuMenu2.Caption = "Extras" mnu21Optionen = New Menu(mnuMenu2) As "mnuOptionen" mnu21Optionen.Caption = "Optionen" mnu21Optionen.Picture = Picture["icon:/16/options"] mnu22SelectColor = New Menu(mnuMenu2) As "mnuSelectColor" mnu22SelectColor.Caption = "Colour palettes" mnu22SelectColor.Picture = Picture["icon:/16/fill"] mnu221Palette1 = New Menu(mnu22SelectColor) As "mnuPalette1" mnu221Palette1.Caption = "Colour chart 1" mnu221Palette1.Picture = Picture["icon:/16/pen"] mnuSpace = New Menu(mnu22SelectColor) mnuSpace.Caption = "" ' Separation line mnu222Palette2 = New Menu(mnu22SelectColor) As "mnuPalette2" mnu222Palette2.Caption = "Colour chart 2" mnu222Palette2.Picture = Picture["icon:/16/color"] mnu23PreView = New Menu(mnuMenu2) As "mnuPreView" mnu23PreView.Caption = "Preview" mnu23PreView.Checked = True mnu23PreView.Toggle = True ... End ' Form_Menu()