[SOLVED] Proper handling of Checkbox Gadget ??

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 1162
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

[SOLVED] Proper handling of Checkbox Gadget ??

Post 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
Last edited by Randy Walker on Fri Nov 07, 2025 10:37 pm, edited 1 time in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
mk-soft
Always Here
Always Here
Posts: 6388
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Proper handling of Checkbox Gadget ??

Post 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
Last edited by mk-soft on Fri Nov 07, 2025 9:23 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5008
Joined: Sun Apr 12, 2009 6:27 am

Re: Proper handling of Checkbox Gadget ??

Post by RASHAD »

Hi Randy
Your checkbox id is 2 not 1
And better use

Code: Select all

If GetGadgetState(2) = 1
Egypt my love
User avatar
mk-soft
Always Here
Always Here
Posts: 6388
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Proper handling of Checkbox Gadget ??

Post 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 !
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Randy Walker
Addict
Addict
Posts: 1162
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Re: Proper handling of Checkbox Gadget ??

Post 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
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
Piero
Addict
Addict
Posts: 1102
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Proper handling of Checkbox Gadget ??

Post 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
Randy Walker
Addict
Addict
Posts: 1162
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Re: Proper handling of Checkbox Gadget ??

Post 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?
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
Piero
Addict
Addict
Posts: 1102
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Proper handling of Checkbox Gadget ??

Post 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
Post Reply