BB___BMPBUTTON

=BMPBUTTON= toc

Description
> A BMPBUTTON is a //control// that a user clicks to initiate an action in a program that has a Graphical User Interface (GUI). Bmpbuttons display an image to convey their purpose, rather than a caption.

Syntax Notes

 * 1) **filespec** Contains the path and file name of the bitmap to be displayed on the button face.
 * 2) **returnVar** is normally a branch label or subroutine.
 * 3) **returnVar** The returnVar may also be an unquoted word that begins with a letter, but can contain numerals. It cannot be a string variable. If this form is used, then the value of returnVar is available to be read when the program is halted at an **input var$** statement. The value will be placed into the specified variable. See Examples.
 * 4) **Button Size** There is no parameter for height and width. The size of the bmpbutton is determined by the size of the bitmap.
 * 5) Without a unique .extension, the bmpbutton cannot receive commands after window is opened.

Button Features
> You can change image to solid rectangle of background color then disable - that's closest you can do to removing button.
 * //**Changing the Image.**// The image can be changed after the window is opened by first loading a bitmap image with the command LOADBMP, and then by printing the command to the bmpbutton. See BITMAP.
 * //**Clicking the Bmpbutton.**// A bmpbutton is clicked (acted on) either by mouse click or by pressing an Enter key or Space key, when the button has the "input focus". The user can click a button, and the button can receive the input, when a SCAN statement is encountered in the program, or when the program is halted with either an INPUT or a WAIT statement.
 * //**Program Flow**// Clicking a button causes program flow to branch to the branchLabel or subName listed in the BMPBUTTON declaration. If the unquoted single word form is used for the **returnVar**, then program flow is halted at an **input var$** statement where the value associated with the bmpbutton being clicked will be placed in **var$**. See Examples.

Bmpbutton Commands
The following commands (Methods) can be used with bmpbuttons. See the individual pages for discussion. print #handle.ext, "bitmap bitmapname" print #handle.ext, "disable" print #handle.ext, "enable" print #handle.ext, "setfocus"

Example

 * Some of the examples below are copied from the JustBASIC Help files. To try these examples, create a blank file named "sampleDemos.bas" (or a similar name) and save it to the JB program folder. Then paste an example into that .bas file and run it. The bitmap images are in the bmp subfolder of your JB program folder and will be found by the example program. **

code format="lb" bmpbutton #main.arrow, "bmp\arrwbttn.bmp", [arrowClicked], UL, 10, 10 open "Button Example" for window as #main
 * An example that uses a branch label button handler.**

[loop] wait

[arrowClicked] notice "The arrow button was clicked. Goodbye." close #main end code

code format="lb" bmpbutton #main.arrow, "bmp\arrwbttn.bmp", arrowClicked, UL, 10, 10 open "Button Example" for window as #main
 * An example that uses a subroutine button handler.**

[loop]

wait

sub arrowClicked bttnHandle$ notice bttnHandle$;" was clicked. Goodbye." close #main end end sub code

code format="lb" bmpbutton #main.arrow, "bmp\arrwbttn.bmp", yes, UL, 10, 10 bmpbutton #main.button2, "bmp\bluebttn.bmp", no, UL, 70, 10 open "Use Input Example" for window as #main
 * An example that retrieves a value with an input statement.**
 * 1) main "trapclose [quit]"

[loop] input answer$ if answer$ = "yes" then notice "You clicked the arrow button."

if answer$ = "no" then notice "You clicked the blue button." goto [loop]

[quit] close #main end code

code format="lb" 'bitmap.bas 'demonstrate the bitmap command for bmpbuttons 'clicking the buttons causes the bitmap images 'displayed on the buttons to change WindowWidth = 248 WindowHeight = 175 nomainwin loadbmp "arrow", "bmp\arrwbttn.bmp" loadbmp "blue", "bmp\bluebttn.bmp" bmpbutton #main.button1, "bmp\blank4.bmp", [button1Click], UL, 22, 11 bmpbutton #main.button2, "bmp\blank4.bmp", [button2Click], UL, 22, 46 open "BmpButton Image Changer" for window as #main print #main, "trapclose [quit]"
 * An example that changes the bitmap images.**

'wait here for user events wait

[button1Click]  'Display arrow image on button 2

print #main.button2, "setfocus" print #main.button2, "bitmap arrow" print #main.button1, "bitmap blue" wait

[button2Click]  'Display arrow image on button 1 print #main.button1, "setfocus" print #main.button1, "bitmap arrow" print #main.button2, "bitmap blue" wait

[quit] close #main end code

Useful Functions
code format="lb" Place a useful function using this command here code