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

List Boxes - Elements - Hag GUI for Cobra - Static

Main Article

List Boxes - Elements - Hag GUI for Cobra

List Boxes using the XP theme.

List boxes are large rectangular elements containing a list of options. Each option can be individually styled or disabled.

As options can extend beyond the height of the box, Hag list box elements automatically create and manage a scrollbar element.

Listboxes expose the following read-only variables:

listbox.x: Integer - Listbox x position
listbox.y: Integer - Listbox y position
listbox.w: Integer - Listbox width
listbox.h: Integer - Listbox height
listbox.enabled: Boolean - If listbox is enabled
listbox.visible: Boolean - If listbox is visible
listbox.gotUpdated: Boolean - If listbox got updated

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


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

   frmMain: ^forms
       lbxMain: ^listBoxes
       btnBold, btnAdd, btnClear, btnClose: ^buttons
       lopHandle: ^listOptions
   background: Element
   i: Integer = 1


   SetAppName("ListBox example")
   OpenScreen(320, 240, 32, FALSE, COB_SHOWBORDER+COB_SHOWCLOSE)
   background = CreateSprite(320,240)
   Cls(ToRGBA(235,233,237),background) ; Flip

   HagInit(320, 240, 1)
   frmMain = CreateForm()
       lbxMain = CreateListBox(frmMain, 20, 20, 280, 180)
       btnAdd = CreateButton(frmMain, 130, 207, 50, "Add")
       btnClear = CreateButton(frmMain, 190, 207, 50, "Clear")
       btnClose = CreateButton(frmMain, 250, 207, 50, "Close")
       btnBold = CreateButton(frmMain, 70, 207, 50, "Bold")
   ListBoxAddOption(lbxMain, "Click on an option to select it")
   ListBoxAddOption(lbxMain, "Use 'Bold' button to bold selected option")
   lopHandle = ListBoxAddOption(lbxMain, "This option has a custom style & color")
       ListOptionFontStyle(lbxMain, lopHandle, 2) // Itallic
       ListOptionFontColor(lbxMain, lopHandle, ToRGBA(0,0,255))

   lopHandle = ListBoxAddOption(lbxMain, "This option is disabled")
       EnableListOption(lbxMain, lopHandle, FALSE)
   ListBoxAddOption(lbxMain, "Click 'Add' to add some more options")
   ListBoxAddOption(lbxMain, "Click 'Clear' to remove all options")
   ListBoxAddOption(lbxMain, "This is another listbox option")
   ListBoxAddOption(lbxMain, "This is yet another listbox option")
   ListBoxAddOption(lbxMain, "This is a further listbox option")
   ListBoxAddOption(lbxMain, "This is another listbox option")
   ListBoxAddOption(lbxMain, "This is an additional listbox option")
   ListBoxAddOption(lbxMain, "This is another listbox option")
   ListBoxAddOption(lbxMain, "This is one more listbox option")
   While ExitRequested = FALSE

       If ButtonClicked(btnBold) then
ListBoxSelectionExists(lbxMain) then
               lopHandle = ListBoxSelectionHandle(lbxMain)
               ListOptionFontStyle(lbxMain, lopHandle, 1)
               MessageBox("No option is selected - can't bold.", "Notice")
ButtonClicked(btnAdd) then
           ListBoxAddOption(lbxMain, "Another listbox option ("+i+")")
ButtonClicked(btnClear) then
           i = 1
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.