User Tools

Site Tools


k13:k13.2:start

The easiest way to equip your program with a menu (→ Figure 13.2.4) is to use the menu editor. It is a good plan if you record this structure - especially with a complex menu structure - and then map it in a table:

NameLevelGroupCaptionActionDayShortcutVETC
mnu1Menu0~Picturefile~~CTRL+W++~~
mnu11Open1~Open…OpenImage CTRL+O++~~
mnu12New1~New~~CTRL+N++~~
mnu13Space1~~~~~++~~
mnu14Print1~Print~~CTRL+P+~~~
mnu15Close1~ExitFormClose~CTRL+Q++~~
mnu2Menu0~Extras~~~++~~
mnu21Options1~Options~~~++~~
mnu22SelectColor1~Select color~~~++~~
mnu221Palette12~Colourchart1~~~++~~
mnu222Space2~~~~~++~~
mnu223Palette22~Colourchart2~~~++~~
mnu23PreView1~Preview~~~++~~
mnu3Menu0~Help~~~++~~
mnu31Help1~HelpHelpMe~F1++~~
mnu32Web1~Onlinehelp~~~++~~

Table 13.2.1: Menu structure (V=Visible, E=Enabled, T=Toogle and C=Checked)

Menüeditor-Icon
Start the menu editor

  • by clicking on the Menu Editor button in the menu bar (above the form),
  • with the key combination CTRL+E or
  • after clicking the right mouse button on the form in which you activate the menu editor entry from the context menu that opens.

Menüeditor 1
Figure 13.2.1: (partial) view of the menu editor

When you create a menu structure, the following steps have been tried and tested:

  • A click on the Insert button in the menu editor creates a new menu entry.Enter the information from your table in the upper and lower part of the menu editor for each menu item → figure 13.2.1 and → figure 13.2.2.You can correct (change or delete) your entries at any time.
  • If you leave the text field blank at Caption, a dividing line between two menu entries is automatically created in the menu at runtime. The name of the menu item only appears in the menu editor in light grey.
  • Change the level of a menu item by selecting the menu item and then increasing or decreasing the level using the two indent and move buttons. The small dots in front of the menu item indicate the current level. In the menu editor, you can recognize a menu item of level zero by its font style bold.
  • You can move a menu item with the two buttons' Move up' and' Move down' in the menu structure. Please make sure that you adjust the names of the menu entries if this name indicates a ranking and sequence.
  • Assign a suitable icon from the collection of gambas to the individual menu entries if you want to follow the usual practice with menu entries.
  • Check all entries in the menu editor carefully before closing the menu editor.

Menüeditor2
Figure 13.2.2: (Part) view2 of the menu editor

Confirm all entries or changes in the menu editor with OK. When you close the menu editor although you have made changes, the system asks whether you want to save the changes:

Nachfrage
Figure 13.2.3: Save - demand

Entries in the menu editor for Action are only necessary if, for example, you want to use the Action class for synchronization between the menu and an inserted toolbar. The chapter' 13.5 Menu and Toolbar' explains how to implement this synchronization.


Figure 13.2.4: Select 'Exit' menu item

To do this, click on the entry you want to add code as an event handling procedure in the form menu; for example, for the mnu15Close_Click() event:

Public Sub mnu15Close_Click()
  FHelp.Close
  FMain.Close
End ' mnu15Close_Click()

Further procedures (selection):

Public Sub mnu11Open_Click()
  ImageOpen()
  mnu14Print.Enabled = True
End ' mnu11Open_Click()
 
Public Sub mnu15Close_Click()
  FHelp.Close
  FMain.Close
End ' mnu15Close_Click()
 
Public Sub mnu23PreView_Click()
  If mnu23PreView.Checked = True Then
     Message.Info("Show preview or" & gb.NewLine & "Generate preview image or...")
  Endif ' Checked = True
End ' mnu23PreView_Click()
 
Public Sub mnu31Help_Click()
  FHelp.Show
End ' mnu31Help_Click()
 
Public Sub mnu32Web_Click()
  Desktop.Open("http://www.gambas-buch.de/dw/doku.php?id=k13:start")
End ' mnu32Web_Click()

Note that you cannot assign procedures to all menu entries. This applies, for example, to all entries of level 0 as well as to entries that contain further entries as (sub-)menus as in mnu22SelectColor.

Whether you make entries in the Tag text field (data type Variant) depends on whether you later evaluate this entry in the program and react depending on the evaluation result.

In the example FNotepad 3.0.0 in the Gambas examples it is demonstrated that you can also select a menu at runtime of the program via ALT+underlined_letters, if you prefix the selected letter with a & sign in front of the entry' Caption'. For example, the combination ALT+a calls the save dialog:

Menue_2
Figure 13.2.5: (Part) view3 of the menu editor

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.2/start.txt · Last modified: 02.02.2022 (external edit)

Page Tools