Jump to content
Sign in to follow this  
buymeapc

Use A Custom Checkbox State Image?

Recommended Posts

buymeapc
Posted (edited)

Hi all,

Does anyone know how to change the state (checked/unchecked) image of a checkbox control? I'd like to use custom icons for checked/unchecked states when the control is clicked. Is it even possible?

Thanks!

Edit: Here's how I'm doing it now, which isn't very elegant

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $g__bBool = False
$hGUI = GUICreate("Test", 200, 200)

$idIcon = GUICtrlCreateIcon("C:\Users\username\Documents\checkbox_empty.ico", 0, 10, 70, 13, 13)
$idLabel = GUICtrlCreateLabel("      " & "Something", 10, 70, (50 + 18), 17, BitOR($GUI_SS_DEFAULT_LABEL, $SS_NOTIFY))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idIcon, $idLabel
            $g__bBool = Not $g__bBool
            If $g__bBool Then
                GUICtrlSetImage($idIcon, "C:\Users\username\Documents\checkbox_filled.ico", 0, 0)
            Else
                GUICtrlSetImage($idIcon, "C:\Users\username\Documents\checkbox_empty.ico", 0, 0)
            EndIf
    EndSwitch
WEnd

 

Edited by buymeapc

Share this post


Link to post
Share on other sites
Danp2

Have you read the remarks section of GUICtrlSetImage, specificly this portion?

Quote

Images can also be set for Checkbox controls as long as the $BS_PUSHLIKE style is used.

 

Share this post


Link to post
Share on other sites
jdelaney

It seems the image is not on the checkbox itself though...can check help file for

_GUICtrlButton_SetImageList

_GUICtrlButton_SetImage

 


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
buymeapc

Hmm...I don't think I'm quite understanding how to implement this properly. If I use $BS_PUSHLIKE, it looks like a button and not a checkbox. However, if I remove that style and set it back as $BS_AUTOCHECKBOX, I now see the original checkbox and the custom one I'm adding. Also, when I hover over the checkbox, the "checked" icon shows up until I move the mouse cursor away...

#include <GUIButton.au3>
#include <GUIConstantsEx.au3>
#include <GUIImageList.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>

Global $g__bBool = False
$hGUI = GUICreate("Test", 200, 200)

$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, "C:\Users\username\Documents\checkbox_empty.ico")
_GUIImageList_AddIcon($hImage, "C:\Users\username\Documents\checkbox_filled.ico")

;$idCheck = GUICtrlCreateCheckbox("Something", 10, 70, 68, 17, $BS_PUSHLIKE); <<<< This shows a button without a checkbox
$idCheck = GUICtrlCreateCheckbox("Something", 10, 70, 68, 17, $BS_AUTOCHECKBOX); <<<< This looks better, but shows the original *and* custom checkboxes
_GUICtrlButton_SetImageList($idCheck, $hImage)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites
orbs

there is this UDF for tristate checkbox in a treeview control, it uses its own images for the checkboxes of the treeview control. you may learn from that how to apply the same concept to an individual checkbox control. also, if anyone knows how to do this, it would probably be the graphics grand master @UEZ

Share this post


Link to post
Share on other sites
UEZ

@buymeapc: check this out:

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×