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:
Name | Level | Group | Caption | Action | Day | Shortcut | V | E | T | C |
---|---|---|---|---|---|---|---|---|---|---|
mnu1Menu | 0 | ~ | Picturefile | ~ | ~ | CTRL+W | + | + | ~ | ~ |
mnu11Open | 1 | ~ | Open… | OpenImage | CTRL+O | + | + | ~ | ~ | |
mnu12New | 1 | ~ | New | ~ | ~ | CTRL+N | + | + | ~ | ~ |
mnu13Space | 1 | ~ | ~ | ~ | ~ | ~ | + | + | ~ | ~ |
mnu14Print | 1 | ~ | ~ | ~ | CTRL+P | + | ~ | ~ | ~ | |
mnu15Close | 1 | ~ | Exit | FormClose | ~ | CTRL+Q | + | + | ~ | ~ |
mnu2Menu | 0 | ~ | Extras | ~ | ~ | ~ | + | + | ~ | ~ |
mnu21Options | 1 | ~ | Options | ~ | ~ | ~ | + | + | ~ | ~ |
mnu22SelectColor | 1 | ~ | Select color | ~ | ~ | ~ | + | + | ~ | ~ |
mnu221Palette1 | 2 | ~ | Colourchart1 | ~ | ~ | ~ | + | + | ~ | ~ |
mnu222Space | 2 | ~ | ~ | ~ | ~ | ~ | + | + | ~ | ~ |
mnu223Palette2 | 2 | ~ | Colourchart2 | ~ | ~ | ~ | + | + | ~ | ~ |
mnu23PreView | 1 | ~ | Preview | ~ | ~ | ~ | + | + | ~ | ~ |
mnu3Menu | 0 | ~ | Help | ~ | ~ | ~ | + | + | ~ | ~ |
mnu31Help | 1 | ~ | Help | HelpMe | ~ | F1 | + | + | ~ | ~ |
mnu32Web | 1 | ~ | Onlinehelp | ~ | ~ | ~ | + | + | ~ | ~ |
Table 13.2.1: Menu structure (V=Visible, E=Enabled, T=Toogle and C=Checked)
Figure 13.2.1: (partial) view of the menu editor
When you create a menu structure, the following steps have been tried and tested:
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:
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: