BMPBUTTON

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

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

  1. BMPBUTTON #handle.ext, filespec, returnVar, cor, x, y
  2. BMPBUTTON #handle, filespec, returnVar, cor, x, y

Syntax Notes

  • filespec Contains the path and file name of the bitmap to be displayed on the button face.
  • returnVar is normally a branch label or subroutine.
  • 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.
  • Button Size There is no parameter for height and width. The size of the bmpbutton is determined by the size of the bitmap.
  • Without a unique .extension, the bmpbutton cannot receive commands after window is opened.

Button Features

  • 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 #handle.ext "bitmap bitmapName" to the bmpbutton. See BITMAP.
You can change image to solid rectangle of background color then disable - that's closest you can do to removing button.
  • 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.

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.

An example that uses a branch label button handler

bmpbutton #main.arrow, "bmp\arrwbttn.bmp", [arrowClicked], UL, 10, 10
open "Button Example" for window as #main

[loop]
    wait

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

An example that uses a subroutine button handler

bmpbutton #main.arrow, "bmp\arrwbttn.bmp", arrowClicked, UL, 10, 10
open "Button Example" for window as #main

[loop]
    wait

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

An example that retrieves a value with an input statement

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
#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

An example that changes the bitmap images

  '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]"

  '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

Useful Procedures

' Place a useful function using this keyword here