User Tools

Site Tools


k13:k13.1:k13.1.1:start

Baumstruktur
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.

  • Menus are created only with the stereotype MenuItem AS Menu/ and the assigned properties. The advantage is the speed with which you can also define extensive and nested menus. A disadvantage is the fact that once set properties can no longer be changed or read out at runtime of the program. Under www.gambas-club.de different variants are presented and controversially discussed under the heading' How to create menu + submenus by code'.
  • Definition of a menu structure with a suitable control structure in the source code. This gives the menus different but automatically assigned captions, but they all have the same name. Therefore, the event handler only knows this one name for all menu actions under which events are triggered. However, you can use the Last. text property to determine which menu object triggered an event and can react to it in a targeted way, where Last is a reference to the last object that triggered an event. At http://de.wikibooks.org/wiki/Gambas:_Men%C3%BC you will find a well-documented example.
  • Definition of individual menus in a specific structure. Note: The order of the defined menus in the source code and their properties determines their arrangement on the form, not the names used (pseudo-numbering, menu identifiers).

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()
The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k13/k13.1/k13.1.1/start.txt · Last modified: 02.02.2022 (external edit)

Page Tools