Radio Buttons - Elements - Hag GUI for Cobra
Radio buttons are small GUI elements belonging to a "Radio Group". Only one radio button per group can be selected at any one time.
Radio groups expose the following read-only variables:
radiogroup.x: Integer - Radio group x position
radiogroup.y: Integer - Radio group y position
radiogroup.enabled: Boolean - If radio group is enabled
radiogroup.visible: Boolean - If radio group is visible
Radio buttons expose the following read-only variables:
radiobutton.x: Integer - Radio button x position
radiobutton.y: Integer - Radio button y position
radiobutton.w: Integer - Radio button width
radiobutton.h: Integer - Radio button height
radiobutton.enabled: Boolean - If radio button is enabled
radiobutton.visible: Boolean - If radio button is visible
For a ready-to-run example, see Example_Radiobuttons in the Examples download.
Example:
Uses
cobra2d,
hagC2d,
keyset
Var
background: Element
i: Integer
frmMain: ^forms
cbxMain: ^checkboxes
rdoGroup, rdoGroup2: ^radioGroups
rdoMain: Array [7] of ^radioButtons
btnClose: ^buttons
fraRight: ^frames
rdoButtonEnabled: Array [2] of ^radioButtons
Begin
SetAppName("Radio Button 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
HagLoadGuiTheme("XP")
frmMain = CreateForm()
cbxMain = CreateCheckbox(frmMain, 20, 20, 120, "Enable Options", TRUE)
rdoGroup = CreateRadioGroup(frmMain)
For i = 0 to 6
rdoMain[i] = CreateRadioButton(rdoGroup, 40, 50+((i)*25), 120, "Option "+(i+1), (i=0))
Next
fraRight = CreateFrame(frmMain, 140, 60, 160, 120, FRAME_STYLE_ROUNDBORDER, "Extended Options")
rdoGroup2 = CreateRadioGroup(frmMain)
rdoButtonEnabled[0] = CreateRadioButton(rdoGroup2, 160, 100, 120, "Button Enabled", TRUE)
rdoButtonEnabled[1] = CreateRadioButton(rdoGroup2, 160, 120, 120, "Button Disabled", FALSE)
btnClose = CreateButton(frmMain, 200, 200, 100, "Close Program")
While Not ExitRequested
If CheckBoxClicked(cbxMain) then EnableRadioGroup(rdoGroup, CheckBoxChecked(cbxMain), TRUE)
If SelectedRadioButtonExists(rdoGroup2) then
If (SelectedRadioButton(rdoGroup2) = rdoButtonEnabled[0]) and (btnClose.enabled = FALSE) then EnableButton(btnClose)
If (SelectedRadioButton(rdoGroup2) = rdoButtonEnabled[1]) and (btnClose.enabled = TRUE) then DisableButton(btnClose)
Endif
HagUpdateAll_AutoKeys()
Flip
Pause(1)
If ButtonClicked(btnClose) then RequestExit
If KeyHits(VK_ESCAPE) > 0 then RequestExit
Wend
End
Stay Subscribed
RSS feed or get updates by e-mail.
, subscribe to theYou can also contact me directly - I make an effort to reply to every e-mail.