Page 1 of 1

[SOLVED] Proper handling of Checkbox Gadget ??

Posted: Fri Nov 07, 2025 9:09 pm
by Randy Walker
I've tried to approach this from many angles but can't seem to nail it down. The box does not fill when I click on it and cannot capture the change:

Code: Select all

If OpenWindow(0, 0, 0, 132, 75, "CheckboxGadget Flag", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CheckBoxGadget(2, 8, 10, 106, 20, "Show Password")
  Repeat
    ev = WaitWindowEvent()
    Select ev
      Case #PB_Event_Gadget
        If GetGadgetState(1) = #PB_Checkbox_Checked
          Debug "Checked"
        Else
          Debug "UnChecked"
        EndIf
    EndSelect
  Until ev = #PB_Event_CloseWindow
EndIf

Re: Proper handling of Checkbox Gadget ??

Posted: Fri Nov 07, 2025 9:19 pm
by mk-soft
Tips ;)

Code: Select all

;- TOP

; Use always EnableExplicit, to find typos
EnableExplicit

; Use Enumerations, to avoid incorrect numbers

Enumeration FormWindows
  #Main
EndEnumeration

Enumeration FormMenuBars
  ;
EndEnumeration

Enumeration FormMenuItems
  ;
EndEnumeration

Enumeration FormGadgets
  #MainCheckbox
EndEnumeration

Global ev

If OpenWindow(#Main, 0, 0, 132, 75, "CheckboxGadget Flag", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CheckBoxGadget(#MainCheckbox, 8, 10, 106, 20, "Show Password")
  Repeat
    ev = WaitWindowEvent()
    Select ev
      Case #PB_Event_CloseWindow
        Select EventWindow()
          Case #Main
            Break
            
        EndSelect
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #MainCheckbox
            If GetGadgetState(#MainCheckbox) = #PB_Checkbox_Checked
              Debug "Checked"
            Else
              Debug "UnChecked"
            EndIf
            
        EndSelect
        
    EndSelect
  ForEver
EndIf

Re: Proper handling of Checkbox Gadget ??

Posted: Fri Nov 07, 2025 9:20 pm
by RASHAD
Hi Randy
Your checkbox id is 2 not 1
And better use

Code: Select all

If GetGadgetState(2) = 1

Re: Proper handling of Checkbox Gadget ??

Posted: Fri Nov 07, 2025 9:26 pm
by mk-soft
RASHAD wrote: Fri Nov 07, 2025 9:20 pm Hi Randy
Your checkbox id is 2 not 1
And better use

Code: Select all

If GetGadgetState(2) = 1
#PB_CheckBox_Checked is right !

Re: Proper handling of Checkbox Gadget ??

Posted: Fri Nov 07, 2025 10:36 pm
by Randy Walker
Thank you RASHAD and Thank you mk-soft.
My real goal was trying to create a Show Password Checkbox but I found a really great solution from Piero: viewtopic.php?p=634703#p634703

Re: Proper handling of Checkbox Gadget ??

Posted: Sat Nov 08, 2025 11:35 am
by Piero
Randy Walker wrote: Fri Nov 07, 2025 10:36 pmI found a really great solution from Piero: viewtopic.php?p=634703#p634703
Huh? Did you mean/forget this? :)
viewtopic.php?t=87334

Re: Proper handling of Checkbox Gadget ??

Posted: Sun Nov 09, 2025 12:13 am
by Randy Walker
Piero wrote: Sat Nov 08, 2025 11:35 am Huh? Did you mean/forget this? :)
viewtopic.php?t=87334
Huh? I would not want to restrict users to numeric only passwords. Who does that?

Re: Proper handling of Checkbox Gadget ??

Posted: Sun Nov 09, 2025 12:42 am
by Piero
Randy Walker wrote: Sun Nov 09, 2025 12:13 am
Piero wrote: Sat Nov 08, 2025 11:35 am Huh? Did you mean/forget this? :)
viewtopic.php?t=87334
Huh? I would not want to restrict users to numeric only passwords. Who does that?

Code: Select all

Global StringGadgetFlags ; = #PB_String_Numeric ; set to 0 for normal password