Sign in to follow this  
Followers 0
Jayson

Problem with coloring checkbox

11 posts in this topic

#1 ·  Posted (edited)

Hello guys ! Since i'm making an alarm clock I display every day of the week by checkboxs with some colored label but i ran into a problem..

With normal checkbox the text is closer to the control but when I'm trying to get the text closer with the custom function the checkbox overlap the colored text. I've tried to change the dimension of the checkbox but it ain't working like i would like  >_<

If you don't understand what I mean't (sorry for my english), try and run this code. 19 is the closest i can go w/o overlapping anything.

#include <GUIConstantsEx.au3>

$Main = GUICreate('', 110, 100)
$CheckBox1 = GUICtrlCreateCheckbox('Some Text', 10, 10, 80, 20)
$aCBox = _GUICtrlCreateCheckbox('Some Text', 10, 30, 55, 20, 0xFF0000)
$aCBox1 = _GUICtrlCreateCheckbox('Some Text1', 10, 70, 60, 20, 0xFF0000)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aCBox[1]
;
        Case $aCBox[2]
            If (GUICtrlRead($aCBox[1]) == $GUI_CHECKED) Then
                GUICtrlSetState($aCBox[1], $GUI_UNCHECKED)
            Else
                GUICtrlSetState($aCBox[1], $GUI_CHECKED)
            EndIf
        Case $aCBox1[1]
;
        Case $aCBox1[2]
            If (GUICtrlRead($aCBox1[1]) == $GUI_CHECKED) Then
                GUICtrlSetState($aCBox1[1], $GUI_UNCHECKED)
            Else
                GUICtrlSetState($aCBox1[1], $GUI_CHECKED)
            EndIf
    EndSwitch
WEnd

Func _GUICtrlCreateCheckbox($sText, $nLeft, $nTop, $nWidth, $nHeight, $nColor)
    Local $aCBoxEx[3]
    $aCBoxEx[1] = GUICtrlCreateCheckbox('', $nLeft, $nTop, -1, 0)
    $aCBoxEx[2] = GUICtrlCreateLabel($sText, $nLeft + 19, $nTop + 3, $nWidth, $nHeight)
    GUICtrlSetColor(-1, $nColor)
    Return $aCBoxEx
EndFunc
Edited by Jayson

Share this post


Link to post
Share on other sites



Hi Jayson,

  not positive what you are looking for but this fixes the overlap...

$CheckBox1 = GUICtrlCreateCheckbox(' Some Text', 10, 10, 80, 20)
$aCBox = _GUICtrlCreateCheckbox(' Some Text', 10, 30, 55, 20, 0xFF0000)
$aCBox1 = _GUICtrlCreateCheckbox(' Some Text1', 10, 70, 60, 20, 0xFF0000)

Share this post


Link to post
Share on other sites

Why not just color the checkbox text?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

 

Hi Jayson,

  not positive what you are looking for but this fixes the overlap...

$CheckBox1 = GUICtrlCreateCheckbox(' Some Text', 10, 10, 80, 20)
$aCBox = _GUICtrlCreateCheckbox(' Some Text', 10, 30, 55, 20, 0xFF0000)
$aCBox1 = _GUICtrlCreateCheckbox(' Some Text1', 10, 70, 60, 20, 0xFF0000)

I've tried that. I want the text closer as the regular function instead of adding space since there will be lots of stuff on my gui but thanks for your help :)

Why not just color the checkbox text?

Using GuiCtrlSetColor isn't working on checkbox unless you destroy the theme and i don't want to do that.

Edited by Jayson

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You can also use a label under the checkbox set its color then disable it too. ( I think I have done that before.

Good Luck

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Just playin around....

This looks interesting needs some work though

line 36

needs

#include <ButtonConstants.au3>

$aCBoxEx[1] = GUICtrlCreateCheckbox('', $nLeft, $nTop, -1, 0, 0x0020)
Edited by l3ill

Share this post


Link to post
Share on other sites

If you want to color the text for the checkbox add this line after every checkbox creation line. See if that helps.

DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", -1, "wstr", 0, "wstr", 0)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

 

Just playin around....

This looks interesting needs some work though

line 36

needs

#include <ButtonConstants.au3>

$aCBoxEx[1] = GUICtrlCreateCheckbox('', $nLeft, $nTop, -1, 0, 0x0020)

Wow ! It work very well that way ! Thanks alot !! :)

 

If you want to color the text for the checkbox add this line after every checkbox creation line. See if that helps.

DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", -1, "wstr", 0, "wstr", 0)

I've already used that but i don't really like the outcome unfortunately

Edited by Jayson

Share this post


Link to post
Share on other sites

I encounter another problem using the custom command.. I always get 0 for check/uncheck box instead of 1/4.. Guess I have no other choice than making them separate.. :(

Share this post


Link to post
Share on other sites

I use a UDF named _SetThemeAppProperties() to set the theme of the GUI so colored ctrls can happen. In latest 3.3.10.0+ I notice the _WinAPI_SetThemeAppProperties() exists in the STD includes which does much the same. This may suit your GUI.

; 3.3.8.1
;~ _SetThemeAppProperties(1)

; 3.3.10.0 +
#include <WinAPITheme.au3>
_WinAPI_SetThemeAppProperties($STAP_ALLOW_NONCLIENT)

#include <GUIConstantsEx.au3>

$Main = GUICreate('', 110, 100)
$CheckBox1 = GUICtrlCreateCheckbox('Some Text', 10, 10, 80, 20)
GUICtrlSetColor(-1, 0xFF0000)
$aCBox = _GUICtrlCreateCheckbox('Some Text', 10, 30, 55, 20, 0xFF0000)
$aCBox1 = _GUICtrlCreateCheckbox('Some Text1', 10, 70, 60, 20, 0xFF0000)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aCBox[1]
;
        Case $aCBox[2]
            If (GUICtrlRead($aCBox[1]) == $GUI_CHECKED) Then
                GUICtrlSetState($aCBox[1], $GUI_UNCHECKED)
            Else
                GUICtrlSetState($aCBox[1], $GUI_CHECKED)
            EndIf
        Case $aCBox1[1]
;
        Case $aCBox1[2]
            If (GUICtrlRead($aCBox1[1]) == $GUI_CHECKED) Then
                GUICtrlSetState($aCBox1[1], $GUI_UNCHECKED)
            Else
                GUICtrlSetState($aCBox1[1], $GUI_CHECKED)
            EndIf
    EndSwitch
WEnd

Func _GUICtrlCreateCheckbox($sText, $nLeft, $nTop, $nWidth, $nHeight, $nColor)
    Local $aCBoxEx[3]
    $aCBoxEx[1] = GUICtrlCreateCheckbox('', $nLeft, $nTop, -1, 0)
    $aCBoxEx[2] = GUICtrlCreateLabel($sText, $nLeft + 19, $nTop + 3, $nWidth, $nHeight)
    GUICtrlSetColor(-1, $nColor)
    Return $aCBoxEx
EndFunc

Func _SetThemeAppProperties($nFlags)
    ; Additional info to SetThemeProperties-value:
    ; 0 = disallow visual styles for all controls/nonclient areas
    ; 1 = disallow for nonclient areas (like border, etc)
    ; 2 = disallow for normal controls
    ; 4 = disallow for web contents.
    If FileExists(@SystemDir & '\uxtheme.dll') Then
        DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', $nFlags)
    EndIf
EndFunc

I commented the call to _SetThemeAppProperties() though if your using 3.3.8.1 then you may use that and use _WinAPI_SetThemeAppProperties() if you have 3.3.10.0+. The GUI seems fine to me on Win7 with aero theme on. :)

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  
Followers 0