MENU

From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Description

Adds a pull down menu to the window.

Syntax

  1. menu #handle, "title", "menu item", [branchLabel],...
  2. menu #handle, "title", "menu item", subName1,...
Relocating automatic edit menu. See Usage.
  1. menu #handle, "edit"

Hints

#handle is the same as the window #handle.
Both branch labels and subs can be used as event handlers for menu selections.
Use the "&" character in titles and menu items before the character you specify as a hotkey.
Use the "|" pipe symbol to insert a separator between menu items.
The menu command must be placed on one line. Use the line continuation character, "_", to break the line for better readability.

Usage

An automatic edit menu is added to the right end of the menu bar when text-editor controls are added to a window. The edit menu can be moved to a position of your choice by including a dummy "edit" in your menu definitions, in the order you choose. Do not include any menu items or hotkey symbols, "&", in this dummy definition. To place the automatic edit menu in the second position on the menu bar, use this method:
menu #main, "&File", "E&xit", [quit]
menu #main, "edit"
menu #main, "&Help", "&About", [about]
If you use a window of type TEXT, you will get an inset editor control and the automatic File and Edit menus. However, you cannot use the above method to place your added menus after the Edit menu with this window type and an inset editor. Your additional menus will be placed before the File menu.

Example

Using branch labels

' Using branch labels for event handlers
    nomainwin

' Menu definition on one line and with hotkey characters shown.
menu #main, "&Colors", "Red",[choice1], "Blue",[choice2], "Green",[choice3],|, "C&lear",[skip]
statictext #main.msg, "", 10, 10, 200, 20

    open "Menu Test Window" for window as #main
    #main "trapclose [quit]"
    wait

' Branch labels for menu selection event handlers.
[choice1]
    #main.msg "You chose Red"
    wait

[choice2]
    #main.msg "You chose Blue"
    wait

[choice3]
    #main.msg "You chose Green"
    wait

[skip]
    #main.msg "You do not want any color."
    wait

[quit]
    close #main
    end

Using Subs

' Using subs for event handlers
    nomainwin

' Menu definition with line continuation characters.
    menu #main, "&Colors", "Red",    red,_
                           "Blue",   blue,_
                           "Green",  green,_
                           |,_
                           "C&lear", skip
    statictext #main.msg, "", 10, 10, 200, 20

    open "Menu Test Window" for window as #main
    #main "trapclose [quit]"
    wait

' Subs as menu selection event handlers.
sub red
    #main.msg "You chose Red"
end sub

sub blue
    #main.msg "You chose Blue"
end sub

sub green
    #main.msg "You chose Green"
end sub

sub skip
    #main.msg "You do not want any color."
end sub

[quit]
    close #main
    end

Useful Procedures

' Place a useful function or sub using this keyword here