|Liberty BASIC Help Online
MENU #handle, "title", "text", [branchLabel], "text2", [branchLabel2], | , . . .
MENU #handle, "title", "text", subName1, "text2", subName2, |, ...
This command adds a pull down menu to the window at #handle. The item "title" specifies the title of the menu, as seen on the menu bar of the window, and each "text", [branchLabel] pair after the title adds a menu item to the menu, and tells Liberty BASIC where to branch to when the menu item is chosen. A sub can be used as a menu event handler.
The " | " character can optionally be placed between menu items, to cause a separating line to be added between the items when the menu is pulled down.
The " & " character placed in the title and text items for the menu specifies the accelerator placement for each item. The letter directly following the " & " character will act as a hotkey for that menu item, when it is pressed while the user presses and holds down the ALT key. The hotkey appears underlined in the menu display.
The menu command must be contained on one line. To break the line for viewing in the Liberty BASIC editor, use the line continuation character, " _ ".
Here is an example that adds a menu to a graphics window:
menu #geo, "&Colors", "&Red", [setRed], "&Green", [setGreen],_
menu #geo, "&Shapes", "&Rectangle", [asRect], "&Circle",_
[asCircle], "&Line", [asLine]
open "Geometric White-board" for graphics_nsb as #geo
wait ' stop and wait for a menu item to be chosen
Notice that the MENU commands must go before the OPEN statement, and must use the same handle as the window (#geo in this case.
Here is an example that uses subs as event handlers:
menu #main.testing, "Testing", "one", one, "two", two
button #main.close, "Close", quit, UL, 10, 10
open "example" for window as #main
#main "trapclose quit"
sub quit handle$
if instr(handle$, ".") then
handle$ = left$(handle$, instr(handle$, ".")-1)
Textboxes and texteditors cause an automatic EDIT menu to be added to the menu bar. To locate this automatic menu, use the menu command with a menu name of "edit" and no items. Do not include the " & " character in this dummy "edit" menu title. If the location for the automatic "edit" menu is not specified, it will appear at the right end of the menu bar.
Example, locate the edit menu in the second position on the menu bar:
menu #1, "&File", "E&xit", [quit]
menu #1, "edit"
menu #1, "&Help", "&About", [about]
Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/