Sign in to follow this  
Followers 0
SlowCoder74

_GUICtrlButton_SetImageList() doesn't work with GUICtrlSetColor()

5 posts in this topic

I spent quite a while trying to figure out why I couldn't set an icon to my button, using BrewManNH's sample below.  Then I decided to strip the code until I determined why it wouldn't draw.

I found that apparently _GUICtrlButton_SetImageList() doesn't work if GUICtrlSetColor() is used on the same control.

BrewManNH's sample:

My test code:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <guiimagelist.au3>

#Region ### START Koda GUI section ### 
$frmMain = GUICreate("", 730, 530, -1, -1)
$btnClose = GUICtrlCreateButton("Close", 560, 472, 161, 24)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
;GUICtrlSetColor(-1, 0x800000)
GUISetState()
#EndRegion ### END Koda GUI section ###

$hImage = _GUIImageList_Create(16, 16, 5)
_GUIImageList_AddIcon($hImage, "Cancel.ico")
_GUICtrlButton_SetImageList($btnClose, $hImage)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Why is this a problem?  Well, my project has buttons inside group controls.  The group controls have the title text set in a different color.  Since controls within the group controls take on the colors of their parents by default, I have to set the color of each child control individually.  In doing that, _GUICtrlButton_SetImageList() breaks.

Any ideas?

Share this post


Link to post
Share on other sites



SlowCoder74,

Colouring buttons is not a good idea - as several threads have explained in the past. There is a bug deep within the AutoIt core code (which means it will not be fixed any time soon - see #376) which causes all sorts of problems when buttons are coloured - they trap the ENTER key, lose styles 9as you have discovered) and generally misbehave. In my opinion, best not to colour buttons. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba, I would expect nothing less than a near-instant reply from you. ^_^

The bug report you linked only seems to cite GUICtrlSetBkColor(), not GUICtrlSetColor().  Is GUICtrlSetColor() also affected in the same scope?  (I know that sounds like a dumb question, as I'm having problems with it, but one can never be too sure.)

Share this post


Link to post
Share on other sites

SlowCoder74,

I have no idea, but it would not surprise me in the least. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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