How to make the background color of a checkbox transparent ?

Just starting out? Need help? Post your questions and find answers here.
hdt888
User
User
Posts: 47
Joined: Sun Jul 07, 2024 8:42 am

How to make the background color of a checkbox transparent ?

Post 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 ) ?
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 301
Joined: Tue Sep 05, 2017 10:07 am

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

Post 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.
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

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

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

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

Post 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
hdt888
User
User
Posts: 47
Joined: Sun Jul 07, 2024 8:42 am

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

Post 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.
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

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

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

Egypt my love
hdt888
User
User
Posts: 47
Joined: Sun Jul 07, 2024 8:42 am

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

Post by hdt888 »

Great RASHAD !!
The code works smoothly, as expected.
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

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

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