This content is provided AS IS for archive purposes only. Content may be out of date with no guarantee of correctness.

Checkboxes - Elements - Hag GUI for Cobra - Static

Main Article

Checkboxes - Elements - Hag GUI for Cobra

Checkboxes using the XP theme.

Checkboxes are small GUI elements that, when clicked, toggle between being "checked" and "unchecked".

Checkboxes expose the following read-only variables:

checkbox.x: Integer - Checkbox x position
checkbox.y: Integer - Checkbox y position
checkbox.w: Integer - Checkbox width
checkbox.h: Integer - Checkbox height
checkbox.enabled: Boolean - If checkbox is enabled
checkbox.visible: Boolean - If checkbox is visible
checkbox.checked: Boolean - If checkbox is checked

For a ready-to-run example, see Example_Checkbox in the Examples download.


Program (icon:"hag\icons\window.ico")

   background: Element
   i: Integer
   frmMain: ^forms
   cbxMain: Array [7] of ^checkboxes
   btnClose: ^buttons
   fraRight: ^frames
   cbxButtonEnabled: ^checkboxes


   SetAppName("Checkbox Example")
   OpenScreen(320, 240, 32, FALSE, COB_SHOWBORDER + COB_SHOWCLOSE)
   background = CreateSprite(320, 240)
   Cls(ToRGBA(235,233,237),background) ; Flip
   HagInit(640, 480, 1) // use a sprite index of 1 because of the background sprite
   frmMain = CreateForm()
   cbxMain[0] = CreateCheckbox(frmMain, 20, 20, 120, "Enable Options", TRUE)
   For i = 1 to 7
       cbxMain[i] = CreateCheckBox(frmMain, 40, 50+((i-1)*25), 120, "Option "+i, (i mod 2 = 0))
   fraRight = CreateFrame(frmMain, 140, 60, 160, 120, FRAME_STYLE_ROUNDBORDER, "Extended Options")
   cbxButtonEnabled = CreateCheckbox(frmMain, 160, 105, 120, "Enable Button", TRUE)
   btnClose = CreateButton(frmMain, 200, 200, 100, "Close Program")
   While Not ExitRequested

       If CheckBoxClicked(cbxMain[0]) then
i = 1 to 7
               EnableCheckbox(cbxMain[i], CheckBoxChecked(cbxMain[0]))
CheckBoxClicked(cbxButtonEnabled) then
           EnableButton(btnClose, CheckBoxChecked(cbxButtonEnabled))


       If ButtonClicked(btnClose) then RequestExit
       If KeyHits(VK_ESCAPE) > 0 then RequestExit    


Stay Subscribed

@golightlyb, subscribe to the RSS feed or get updates by e-mail.

You can also contact me directly - I make an effort to reply to every e-mail.