Liberty BASIC Help Online

Window and Dialog Commands
 
Note that Liberty BASIC 3 allows tabbing through controls in windows of type "window" as well as in windows of type "dialog."  "Tabbing through the controls" means that controls will be highlighted and receive the input focus, in turn each time the user hits the "TAB" key.  When the user presses the "TAB" key, the next control listed will receive the input focus.
 
Changing the handle of a window dynamically at runtime can be accomplished with the MAPHANDLE command.
 
Dialog Default Button
In a dialog window, one button may be given the extension "default".  If the user presses the ENTER key while in the dialog window, it will be the same as if the button whose extension is "default" is pressed and program execution will continue at the event handler [branchLabel] for that button.  In the example below, the program branches to the [okay] routine when the user presses ENTER.
 
button #win.default, "Okay",[okay],UL,200,100
open "Test" for dialog as #win
 
The "default" extension only works this way for regular buttons, not for bmpbuttons.
 
Change in behavior for LB3:  If any button has focus, it becomes the default button in a dialog window.  If any other kind of control has the focus, the button designated with the ".default" extension is the default button.
 
CURSOR
The mouse pointer, also called the cursor may be changed with the CURSOR command.
 
GENERAL WINDOW AND CONTROL COMMANDS:
 
TRAPCLOSE - This command sets a close event handler for a window or dialog.  When a user decide to close a window, it branches to a routine specified by the "trapclose" command that confirms or does some sort of cleanup, etc.
 
Branch Label for Close
  'trapclose example using a branch label event handler
  statictext #example.label, "Now close the window!!", 10, 10, 200, 25
  open "Demonstrate trapclose" for window as #example
  print #example, "trapclose [branch]"
  wait
 
[branch]
  confirm "Really close?"; answer$
  if answer$ = "no" then wait
  close #example
  end
 
Subroutine for Close
  'trapclose example using a subroutine event handler
  statictext #example.label, "Now close the window!!", 10, 10, 200, 25
  open "Demonstrate trapclose" for window as #example
  print #example, "trapclose Branch"
  wait
 
sub Branch handle$
  confirm "Really close?"; answer$
  if answer$ = "no" then wait
  close #handle$
  end
  end sub
 
To send a trapclose command to text window, precede the command with the ! character.
 
  'trapclose example in text window
  open "Demonstrate trapclose" for text as #example
  print #example, "!trapclose [branch]"
  wait
 
See also:  Trapping the close event
 
FONT - This command sets the font of all of the controls in a window.
 
    'set the font of all the controls in a
  'window to courier new 8pt italic
  print #handle, "font courier_new 8 italic"
 
When using a text window, precede the command with a ! character:
 
  open "Font Test" for text as #handle
  print #handle, "!font courier_new 8 italic"
  wait
 
For more on specifying fonts read How to Specify Fonts
 
To override this general font command, font commands may be sent to individual controls after this command is issued.  See the command listss for individual controls for control-specific documentation.   If a control can accept a new text string such as a caption, the font command must be preceded by a ! character.  Examples:
'some controls require !font
print #h.button, "!font courier_new 8 italic"
print #h.textbox, "!font courier_new 8 italic"
 
'some controls do not require a ! character:
print #h.graphicbox, "font courier_new 8 italic"
print #h.radiobutton, "font courier_new 8 italic"
 
 
RESIZEHANDLER - This command sets up an event handler that is activated when the user resizes a window of type "window". This command is not useful for dialog windows or for windows without a sizing frame.  See also the REFRESH and LOCATE commands below.
 
  'set up a handler for when the user resizes a window
  print #handle, "resizehandler [branch]"
 
or...
  'clear the resizing handler
  print #handle, "resizehandler"
 
See the example program RESIZE.BAS.
 
 
LOCATE - This command is useful when the RESIZEHANDLER command is used (see above).  After a user resizes a window and the resizehandler is invoked, the controls in that window can be resized and positioned using the locate command.  It is necessary to precede the command with a ! character for controls such as buttons and textboxes that can accept a new text string or caption.  See the command lists for individual controls for control-specific documentation.  After this, the REFRESH command is used to redraw the entire window.
 
  'move and size controls
  print #handle.ext, "locate x y w h"
 
  'move and size buttons, textboxes, etc.
  print #handle.ext, "!locate x y w h"
 
In the example above, "x y w h" are standing in for literal values.  To use variables, place them outside the quotation marks and be sure to preserve the blank spaces.
 
  'literals
  print #handle.ext, "locate 12 20 100 24"
 
  'variables
  x=12 : y=20 : w=100 : h=24
  print #handle.ext, "locate ";x;" ";y;" ";w;" ";h
 
See the example program RESIZE.BAS.
 
REFRESH - This command is useful when the RESIZEHANDLER command is used (see above).  After a user resizes a window and the resize handler is invoked, the controls in that window may be resized and positioned using the locate command.  After this, the REFRESH command is used to redraw the entire window.
 
  'update the window
  print #handle, "refresh"
 
See the example program RESIZE.BAS.
 
 
SETFOCUS - Input focus can be set to a control, or to a window with this command.  This means that keyboard input will be directed to the specified control or window.  Begin the command with the ! character for all windows and controls that can accept new text strings, or the command will simply be displayed on the control.  See the topics for individual controls for control-specific documentation. 
 
  'texteditor
  print #handle.texteditor, "!setfocus"
 
  'graphics window
  print #graph, "setfocus"
 
  'button
  print #handle.button, "!setfocus"
 
  'graphicbox
  print #handle.graphicbox, "setfocus"
 
 
ENABLE, DISABLE
These two commands cause a control to be enabled and active, or disabled and inactive. When a control is disabled it appears to be grayed-out. Begin the command with the ! character for all windows and controls that can accept new text strings, or the command will simply be displayed on the control.  See the topics for individual controls for control-specific documentation. 
 
  nomainwin
 
  button #win.bttn, "Hello",[hello],UL,10,70
  checkbox #win.cbox, "Goodbye",[quit],[quit],10,160,120,24
  menu #win, "&Main","&Enable",[doEnable],_
      "&Disable",[doDisable],"E&xit",[quit]
  open "Enable and Disable" for window as #win
 
  wait
 
  [quit] close #win:end
 
  [doEnable]
  #win.bttn "!Enable"
  #win.cbox "Enable"
  wait
 
  [doDisable]
  #win.bttn "!Disable"
  #win.cbox "Disable"
  wait
 
  [hello] wait
 
 
SHOW, HIDE
These two commands cause a control to be visible or hidden. Begin the command with the ! character for all windows and controls that can accept new text strings, or the command will simply be displayed on the control.  See the topics for individual controls for control-specific documentation. 
 
  nomainwin
 
  button #win.bttn, "Hello",[hello],UL,10,70
  checkbox #win.cbox, "Goodbye",[quit],[quit],10,160,120,24
  menu #win, "&Main","&Show",[doShow],_
      "&Hide",[doHide],"E&xit",[quit]
  open "Show and Hide" for window as #win
 
  wait
 
  [quit] close #win:end
 
  [doShow]
  #win.bttn "!Show"
  #win.cbox "Show"
  wait
 
  [doHide]
  #win.bttn "!Hide"
  #win.cbox "Hide"
  wait
 
  [hello] wait


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/