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

Drop-down Boxes - Elements - Hag GUI for Cobra - Static

Main Article

Drop-down Boxes - Elements - Hag GUI for Cobra

Drown-down boxes using the XP theme.

Drop-down boxes are rectangular GUI elements that, when inactive, display a single value. When activated, it displays (drops down) a list of values, from which the user may select one.

Drop-down boxes expose the following read-only variables:

dropdown.x: Integer - Drop-down x position
dropdown.y: Integer - Drop-down y position
dropdown.w: Integer - Drop-down width
dropdown.h: Integer - Drop-down height
dropdown.enabled: Boolean - If drop-down is enabled
dropdown.visible: Boolean - If drop-down is visible
dropdown.txt: String - Currently selected drop-down option

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


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

   background: Element
   i: Integer
   frmMain: ^forms
   fraMain: ^frames
   ddbMain: Array[5] of ^dropDowns
   txtMain: Array[5] of ^hTexts
   btnClose: ^buttons


   SetAppName("Drop-down Box 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()
   fraMain = CreateFrame(frmMain, 20, 20, 280, 180, FRAME_STYLE_ROUNDBORDER, "Options")
   txtMain[0] = CreateText(frmMain, 40, 53, "Colour:", 60)
   ddbMain[0] = CreateDropDown(frmMain, 120, 50, 160, "Select...")
       DropDownAddOption(ddbMain[0], "Red")
       DropDownAddOption(ddbMain[0], "Green")
       DropDownAddOption(ddbMain[0], "Blue")
       DropDownAddOption(ddbMain[0], "White")
       DropDownAddOption(ddbMain[0], "Black")
       DropDownAddOption(ddbMain[0], "Random")
   txtMain[1] = CreateText(frmMain, 40, 83, "Shape:", 60)
   ddbMain[1] = CreateDropDown(frmMain, 120, 80, 160, "Select...")
       DropDownAddOption(ddbMain[1], "Square")
       DropDownAddOption(ddbMain[1], "Circle")
       DropDownAddOption(ddbMain[1], "Triangle")
       DropDownAddOption(ddbMain[1], "Hexagon")

   txtMain[2] = CreateText(frmMain, 40, 113, "Position:", 60)
   ddbMain[2] = CreateDropDown(frmMain, 120, 110, 160, "Select...")
       DropDownAddOption(ddbMain[2], "Left")
       DropDownAddOption(ddbMain[2], "Middle")
       DropDownAddOption(ddbMain[2], "Right")
   txtMain[3] = CreateText(frmMain, 40, 143, "Size:", 60)
   ddbMain[3] = CreateDropDown(frmMain, 120, 140, 160, "Select...")
       DropDownAddOption(ddbMain[3], "Tiny")
       DropDownAddOption(ddbMain[3], "Small")
       DropDownAddOption(ddbMain[3], "Medium")
       DropDownAddOption(ddbMain[3], "Large")
   btnClose = CreateButton(frmMain, 200, 200, 100, "Close Program")
   While Not ExitRequested


       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.