Table of Contents

13.3.1 Option menu

An option menu is a menu with a text and a CheckBox whose value can be toggled between the two states ☑ (activated) and ☐ (deactivated). To implement a menu with this property, you must use the Checked property of a menu. You can set this property in the menu editor or in the source code. The Checked property of a menu corresponds to the Toggle property.

The property Menu.Checked is a synonym for Menu.value and indicates whether the checkmark ☑ is displayed in front of the menu text or not. However, it does not control in any way the behaviour of the option menu! If Menu.Toggle is set, Menu.Checked is inverted automatically when the option menu is clicked.

13.3.1.1 Example 1

In a program that loads and displays images, you want to allow the user to edit the image, among other things. For example, you can create a (sub)menu item mnu21AllowedEdit with the label “Image Editing” in a menu mnuMenu2 with the label “Extras”:

Public Sub CreateAndShowMenus()'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  mnuMenu2 = New Menu(FMain, False) ' Menu bar is displayed
  mnuMenu2.Caption = "Extras"
 
  mnu21AllowedEdit = New Menu(mnuMenu2) As "mnuAllowedEdit"
  mnu21AllowedEdit.Caption = "Image edit"
  mnu21AllowedEdit.Visible = True
 
  mnu21AllowedEdit.Toggle = True
  mnu21AllowedEdit.Checked = False
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~End ' CreateAndShowMenus()

B1
Figure 13.3.1.1.1.1: Checkbox de-activated - Image editing not allowed (default setting)

[1] Public Sub mnuAllowedEdit_Click()
[2]
[3]   If bOpenImage = True Then
[4]      MM.mnu12Edit.Enabled = mnu21AllowedEdit.Checked
[5]   Endif ' bOpenImage = True ?
[6]
[7] End ' mnuAllowedEdit_Click()

B2
Figure 13.3.1.1.1.2: Checkbox activated - image editing allowed

13.3.1.2 Example 2

Example 2 refers to the editor 'Notepad' from the example collection of gambas. In the editor, you can switch the line break in the TextArea text display component on and off. The mnuWrap.Checked = False and mnuWrap.Toggle properties are not set in the menu editor. Therefore, you must switch the checkbox states as in line 3:

[1] Public Sub mnuWrap_Click()
[2]
[3]   mnuWrap.Checked = Not mnuWrap.Checked
[4]   txtNotePad.Wrap = mnuWrap.Checked
[5]
[6] End ' mnuWrap_Click()

B3
Figure 13.3.1.2.1: Checkbox is activated at program startup

B4
Figure 13.3.1.2.2: Checkbox de-activated - line break can be activated


The display of an icon in the menu item 'Line break' on the one hand and the display of an activated checkbox ☑ only succeed if you use either the QT/QTK+ alternate component (gb.gui) or the GTK+ component as Graphical User Interface. The use of the QT4 component causes an error when displaying the provided icon.