Page 1 of 1

How to make the background color of a checkbox transparent ?

Posted: Sat Jul 20, 2024 3:19 pm
by hdt888
I searched all over the forum and tried some codes, but it didn't work as expected.

Any option to remove checkbox background white color ( my window has a dark background image ) ?

Re: How to make the background color of a checkbox transparent ?

Posted: Sat Jul 20, 2024 3:29 pm
by matalog
hdt888 wrote: Sat Jul 20, 2024 3:19 pm I searched all over the forum and tried some codes, but it didn't work as expected.

Any option to remove checkbox background white color ( my window has a dark background image ) ?
If a checkbox gadget colour can be changed and you can change the background colour, then you should set the colour to RGBA(R,G,B,0) - noting that his colour is RGBA and not RGB - then you should set the drawing mode to DrawingMode( #PB_2DDrawing_AlphaBlend) - I'm not certain those things are possible to do though. So you could use the RGBA() value to draw your own, it shouldn't be too hard to code.

Re: How to make the background color of a checkbox transparent ?

Posted: Sat Jul 20, 2024 4:33 pm
by jacdelad
Changing the background colours of Checkboxes is not natively supported, you either need Windows API and custom drawing (if you are on Windows, I guess the others sStmes provide comething similar) or simulate the checkbox, e.g. with a canvas. Take a look at ChrisR's ObjectTheme.

Re: How to make the background color of a checkbox transparent ?

Posted: Sun Jul 21, 2024 3:18 am
by BarryG
hdt888 wrote: Sat Jul 20, 2024 3:19 pmAny option to remove checkbox background white color ( my window has a dark background image ) ?
Here (for Windows only) -> https://www.purebasic.fr/english/viewto ... 96#p624596

Re: How to make the background color of a checkbox transparent ?

Posted: Sun Jul 21, 2024 11:24 am
by hdt888
Thank you BarryG.

The results show like that, right ? (Test by PB 6.10 + win10)

Image

If so, it's not really transparent. This is to set the background color for the CheckBox.

Re: How to make the background color of a checkbox transparent ?

Posted: Sun Jul 21, 2024 12:22 pm
by RASHAD

Code: Select all

Global Bkgcolor

Bkgcolor  = GetStockObject_(#NULL_BRUSH)

CreateImage(0, 400, 300)
StartDrawing(ImageOutput(0))
  For x = 0 To 399
    For y = 0 To 299
      Plot(x,y, RGB(x,y,x*y))
    Next
  Next
StopDrawing()

hBrush = CreatePatternBrush_(ImageID(0))

Procedure WindowProc(hwnd, uMsg, wParam, lParam) 
    Select uMSG
     Case #WM_CTLCOLORSTATIC
      Select GetProp_(lParam, "PB_ID");GetDlgCtrlID_(lParam)
         Case 1 , 2
             SetBkMode_(wParam,#TRANSPARENT)
             SetTextColor_(wParam,#Yellow)
         ProcedureReturn Bkgcolor
      EndSelect        
    EndSelect    
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

OpenWindow(0,0,0,400,300,"test",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
SetWindowCallback(@WindowProc())

CheckBoxGadget(1,10,10,125,20,"CheckBox # 1")
SetWindowTheme_(GadgetID(1), @null.w, @null.w)
CheckBoxGadget(2,10,40,125,20,"CheckBox # 2")
SetWindowTheme_(GadgetID(2), @null.w, @null.w)
Repeat
  Select WaitWindowEvent()
      
       Case #PB_Event_CloseWindow
            Quit = 1
            
       Case #PB_Event_Gadget
          Select EventGadget()
            Case 1,2
                GetWindowRect_(GadgetID(EventGadget()),r.RECT)
                MapWindowPoints_(0,WindowID(0),r,2)
                InvalidateRect_(WindowID(0),r,1)
          EndSelect
  EndSelect
Until Quit = 1

DeleteObject_(Bkgcolor)
DeleteObject_(hBrush)


Re: How to make the background color of a checkbox transparent ?

Posted: Sun Jul 21, 2024 1:06 pm
by hdt888
Great RASHAD !!
The code works smoothly, as expected.

Re: How to make the background color of a checkbox transparent ?

Posted: Mon Jul 22, 2024 4:27 am
by BarryG
hdt888 wrote: Sat Jul 20, 2024 3:19 pmAny option to remove checkbox background white color
You said you want to change the white of the checkbox, but Rashad's code doesn't do that (it's still white). I don't get the request.