Jump to content

Default colour button


JohnOne
 Share

Recommended Posts

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.

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

Link to comment
Share on other sites

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

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.

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...