Can we change the Checkbox Background Color?

Just starting out? Need help? Post your questions and find answers here.
EaxVal
User
User
Posts: 14
Joined: Thu Sep 12, 2024 2:00 pm

Can we change the Checkbox Background Color?

Post by EaxVal »

Hello,
My goal is to create window and a checkbox share the same color. However, I am unable to modify the checkbox's background color in the following code. Any idea?

Code: Select all

If OpenWindow(0, 100, 100, 300, 200, "Checkbox Coloring Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CheckBoxGadget(0, 50, 50, 200, 30, "Sample Checkbox")
  
  SetWindowColor(0, RGB(200, 220, 255))
  SetGadgetColor(0, #PB_Gadget_BackColor, RGB(200, 220, 255))
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Can we change the Checkbox Background Color?

Post by BarryG »

You're fairly new here, so my advice: do a forum search because 99% of requests have been answered.

For your request -> https://www.purebasic.fr/english/viewto ... 96#p624596
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Can we change the Checkbox Background Color?

Post by RASHAD »

Hi

Code: Select all


OpenWindow(0,0,0,400,300,"test",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowColor(0,$909090)

CheckBoxGadget(1,14,15,14,14,"",#WS_CLIPSIBLINGS)
TextGadget(10,10,10,140,24,"     CheckBox # 1",#SS_CENTERIMAGE|#SS_NOTIFY|#WS_CLIPSIBLINGS)
SetGadgetColor(10,#PB_Gadget_BackColor,0)
SetGadgetColor(10,#PB_Gadget_FrontColor,$FFFFFF)

CheckBoxGadget(2,14,45,14,14,"",#WS_CLIPSIBLINGS)
TextGadget(20,10,40,140,24,"     CheckBox # 2",#SS_CENTERIMAGE|#SS_NOTIFY|#WS_CLIPSIBLINGS)
SetGadgetColor(20,#PB_Gadget_BackColor,$00FFFF)
SetGadgetColor(20,#PB_Gadget_FrontColor,$FF0000)
Repeat
  Select WaitWindowEvent()
      
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          set10 = GetGadgetState(1)
        Case 2
          set20 = GetGadgetState(2)
          
        Case 10
          set10 ! 1
          SetGadgetState(1,set10)
          
        Case 20
          set20 ! 1
          SetGadgetState(2,set20)
          
      EndSelect
  EndSelect
Until Quit = 1
Egypt my love
EaxVal
User
User
Posts: 14
Joined: Thu Sep 12, 2024 2:00 pm

Re: Can we change the Checkbox Background Color?

Post by EaxVal »

RASHAD wrote: Tue Apr 15, 2025 3:48 pm Hi
....
......
........

Thank you, RASHAD!
dige
Addict
Addict
Posts: 1405
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Can we change the Checkbox Background Color?

Post by dige »

@RASHAD: thx mate!

I didn't know that yet. that's a very cool and smart workaround for this old problem.

I have a small idea for improvement regarding formatting with spaces. Instead of char(32) I prefer chr($2800), which will not optimized away by thu ui.

Code: Select all


space.s = RSet("", 3, Chr($2800)) 


OpenWindow(0,0,0,400,300,"test",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowColor(0,$909090)

CheckBoxGadget(1,14,15,14,14,"",#WS_CLIPSIBLINGS)
TextGadget(10,10,10,140,24,space + "CheckBox # 1",#SS_CENTERIMAGE|#SS_NOTIFY|#WS_CLIPSIBLINGS)
SetGadgetColor(10,#PB_Gadget_BackColor,0)
SetGadgetColor(10,#PB_Gadget_FrontColor,$FFFFFF)

CheckBoxGadget(2,14,45,14,14,"",#WS_CLIPSIBLINGS)
TextGadget(20,10,40,140,24, space + "CheckBox # 2",#SS_CENTERIMAGE|#SS_NOTIFY|#WS_CLIPSIBLINGS)
SetGadgetColor(20,#PB_Gadget_BackColor,$00FFFF)
SetGadgetColor(20,#PB_Gadget_FrontColor,$FF0000)
Repeat
  Select WaitWindowEvent()
      
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          set10 = GetGadgetState(1)
        Case 2
          set20 = GetGadgetState(2)
          
        Case 10
          set10 ! 1
          SetGadgetState(1,set10)
          
        Case 20
          set20 ! 1
          SetGadgetState(2,set20)
          
      EndSelect
  EndSelect
Until Quit = 1

"Daddy, I'll run faster, then it is not so far..."
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Can we change the Checkbox Background Color?

Post by RASHAD »

@EaxVal
You are welcome
@dige
Thanks mate :)
Egypt my love
Post Reply