RADIOBUTTON

RADIOBUTTON #handle.ext, "label", setHandler, resetHandler, x, y, wide, high

Description

This command adds a radiobutton control to the window referenced by #handle. Radiobuttons have two states, set and reset. They are useful for getting input of on/off type information.

All radiobuttons on a given window are linked together, so that if one is set by clicking on it, all the others will be reset (cleared). The exception to this rule occurs when radiobuttons are placed within the confines of groupboxes. In this case, only radiobuttons contained within the same groupbox act as a radio-set. Clicking (setting) a radiobutton within one groupbox has no effect on radiobuttons that are placed within other groupboxes. See the demo below.

#handle.ext

This specifies handle for this control. The #handle part must be the same as the #handle of the window that contains the radiobutton, and the ".ext" part names the radiobutton uniquely in the window.

"label"

This specifies the visible text of the radiobutton

setHandler

This is the branch label or subroutine executed by the program when the user sets the radiobutton by clicking on it. See also: Controls and Events

resetHandler

This is the branch label or subroutine executed when the user resets the radiobutton by clicking on it. (this doesn't actually do anything because radiobuttons can't be reset by clicking on them).

xOrigin

This is the x position of the radiobutton relative to the upper left corner of the window it belongs to.

yOrigin

This is the y position of the radiobutton relative to the upper left corner of the window it belongs to.

width

This is the width of the radiobutton control

height

This is the height of the radiobutton control

Radiobuttons understand these commands:

print #handle.ext, "set"

This sets the radiobutton.

print #handle.ext, "reset"

This resets the radiobutton.

print #handle.ext, "value? result$"

The result$ variable will be set to the status of the radiobutton (either "set" or "reset").

print #handle.ext, "setfocus"

This causes the radiobutton to receive the input focus. This means that any keypresses will be directed to the radiobutton.

print #handle,ext, "locate x y width height"

This repositions the radiobutton in its window. This is effective when the radiobutton is placed inside window of type "window". The button will not update its size and location until a REFRESH command is sent to the window. See the included RESIZE.BAS example program.

print #handle.ext, "font facename pointSize"

This sets the font to the specified face and point size. If an exact match cannot be found, then Liberty BASIC will try to find a close match, with size taking precedence over face. For more on specifying fonts read How to Specify Fonts

Example:

  print #handle.ext, "font times_new_roman 10"

print #handle.ext, "enable"

This causes the control to be enabled.

print #handle.ext, "disable"

This causes the control to be inactive and grayed-out.

print #handle.ext, "show"

This causes the control to be visible.

print #handle.ext, "hide"

This causes the control to be hidden or invisible.

Usage:

There are two demo programs below.

  'demonstrate radiobuttons with branch label event handlers
  nomainwin
  WindowWidth = 520
  WindowHeight = 220
  groupbox #cfg, "Confirm File Operations:", 240, 20, 200, 140
  radiobutton #cfg.Aalways, "Always", [alwaysConfirm], [nil], 260, 45, 130, 20
  radiobutton #cfg.AwhenReplacing, "When Replacing", _
    [whenReplacingConfirm], [nil], 260, 70, 130, 20
  radiobutton #cfg.Anever, "Never", [neverConfirm], [nil], 260, 95, 130, 20
  groupbox #cfg, "Confirm Close Operations:", 20, 20, 200, 140
  radiobutton #cfg.always, "Always", [alwaysClose], [nil], 40, 45, 130, 20
  radiobutton #cfg.whenReplacing, "When Replacing", _
    [whenReplacingClose], [nil], 40, 70, 130, 20
  radiobutton #cfg.never, "Never", [neverClose], [nil], 40, 95, 130, 20
  button #cfg, " &OK ", [cfgOk], UL, 450, 30
  open "Action Confirmation - Setup" for dialog as #cfg
  print #cfg, "trapclose [cfgOk]"
  print #cfg.Anever, "set"
  print #cfg.never, "set"
  wait

[alwaysConfirm]
  status$ = "Always Confirm"
  wait

[whenReplacingConfirm]
  status$ = "When Replacing Confirm"
  wait

[neverConfirm]
  status$ = "Never Confirm"
  wait

[alwaysClose]
  cstatus$ = "Always Close"
  wait

[whenReplacingClose]
  cstatus$ = "When Replacing Close"
  wait

[neverClose]
  cstatus$ = "Never Close"
  wait

[cfgOk]
  msg$ = status$ + chr$(13) + cstatus$ + chr$(13)
  msg$ = msg$ + "Save this configuration?"
  confirm msg$ ; answer$
  'perform some sort of save for config here
  close #cfg
  end

[nil]
  wait

Here is another example that uses a SUB event handler.  Only one handler is needed with this technique:

  nomainwin
  global status$
  radiobutton #win.yes, "Yes", doRadio, dummy,10,45,130,20
  radiobutton #win.no, "No", doRadio,dummy,10,70,130,20
  open "Make a Choice" for window as #win
  print #win, "trapclose Quit"
  print #win.yes, "set"
  wait

sub doRadio handle$
  notice "You selected ";handle$
  if handle$ = "#win.yes" then status$="yes"
  if handle$ = "#win.no" then status$="no"
end sub

sub Quit handle$
  close #handle$
  end
end sub

Note: see also CHECKBOX

For information on creating controls with different background colors, see Colors and the Graphical User Interface.