Sign in to follow this  
Followers 0
JohnOne

Default colour button

6 posts in this topic

#1 ·  Posted (edited)

I've dynamically changed the colour of a button upon click.

My problem is, how to change it back, I have searched the help without luck getting the colour, or changing it back. I seen that you can set the default colour, but thats no good to me I dont think.

So I tried GUICrtlSetStyle(), and the button returned to its previous colour, except it then disappears when you try to use it again.

Im more than likely missing something. My question is what am I missing here?

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

GUICreate('')
$b1 = GUICtrlCreateButton("button1",10,10)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit

        Case $msg = $b1
            GUICtrlSetBkColor($b1,0x059122)
            Sleep(2000)
            GUICtrlSetStyle($b1,$GUI_SS_DEFAULT_GUI )
    EndSelect
WEnd
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites



Do it so:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

GUICreate('')
$b1 = GUICtrlCreateButton("button1",10,10,60)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUISetState()

$changed = False

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit

        Case $msg = $b1
            $changed = Not $changed
            If $changed Then
                GUICtrlSetBkColor($b1,0x059122)
            Else
                GUICtrlSetBkColor($b1, 0xFFFF00)
            EndIf
    EndSelect
WEnd

Best Regards BugFix  

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You might also do it this way, so that the button changes back to the default color (you don't have to use a new bkcolor):

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>

GUICreate('')
$b1 = GUICtrlCreateButton("button1",10,10)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit

        Case $msg = $b1
            GUICtrlSetBkColor($b1,0x059122)
            Sleep(2000)
            _GUICtrlButton_SetStyle($b1, $GUI_SS_DEFAULT_GUI)
    EndSelect
WEnd
Edited by Michiel78

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks for the suggestion BugFix, except the point is to have the button return to its default themed colouring (which isnt a single colour)

EDIT:

Great, that next one worked

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Cheers Michiel78

You're welcome!

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