Jump to content

Use A Custom Checkbox State Image?


Recommended Posts

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
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...