Jump to content

Change Button Colour?


Recommended Posts

Is it now possible to change the colour of a button (preferably background but otherwise text)?

I can change the font, bold etc, but can't find a way to change the colour. I tried modifying the provided label colour change code...

#include <GUIConstants.au3>

GUICreate("My GUI color text"); will create a dialog box that when displayed is centered

GUICtrlCreateButton ("my Red label", 10,20)
GUICtrlSetColor(-1,0xff0000); Red
                
GUISetState ()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

...but that doesn't work :lmao:

TIA,

Edited by 8daysaweek.co.uk

[size=15]James :)[/size]www.8daysaweek.co.uk - A User-Focused OOo site, with Forums, Help Centre,Easy Installation CDs & OOo on USB Key

Link to comment
Share on other sites

Is it now possible to change the colour of a button (preferably background but otherwise text)?

I can change the font, bold etc, but can't find a way to change the colour. I tried modifying the provided label colour change code...

#include <GUIConstants.au3>

GUICreate("My GUI color text"); will create a dialog box that when displayed is centered

GUICtrlCreateButton ("my Red label", 10,20)
GUICtrlSetColor(-1,0xff0000); Red
                
GUISetState ()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

...but that doesn't work :lmao:

TIA,

Far as I know, no

But you could use another control like a label, or a pic for the control

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

An example using a picture

#include <GUIConstants.au3>
; == GUI generated with Koda ==
$Form1 = GUICreate("AForm1", 622, 448, 192, 125)
$Button1 = GUICtrlCreateButton("(Not allowed)", 128, 56, 137, 65, $BS_BITMAP)
GUICtrlSetImage($Button1, "D:\Temp\red.bmp")
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;;;;;
    EndSelect
WEnd
Exit


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

  • 3 weeks later...

Hey everyone, i am new to programing using Autoit, but i am having lots of fun. Here is my first input to button with color. i created a label with a bkcolor and set an event, i hope that helps.

#include <GUIConstants.au3>

GUICreate("Label disguised as a button"); will create a dialog box that when displayed is centered
Opt("GUIOnEventMode",1)
$mylabel = GUICtrlCreateLabel ("Testing, one two three", 2, 2, 350,35,$BS_DEFPUSHBUTTON+$SS_SUNKEN+$BS_CENTER,$SS_LEFT+$SS_BLACKFRAME)
GUICtrlSetColor(-1,0x082BFE);blue
GUICtrlSetFont(-1,14,4,"","Arial")
GUICtrlSetBkColor(-1,0xF8FA6F); Yellow
GUICtrlSetOnEvent($mylabel, "_Hello")

GUISetState ()  ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
Wend


Func _Hello()
    
    MsgBox(0,"Event","10 sec timeout, exiting...",10)
    Exit
EndFunc

Posted Image

Edited by joseedwin
Link to comment
Share on other sites

  • Moderators

If I remember correctly, Valauter and myself had done something similar here to help someone with a question a while back (many months)... but your approach is nice... I changed it a bit to add notification by color change that the button was pressed... (Notice a few changes (bitor particularly).)

However, I'm sure that GuiRegisterMessage() is probably the better approach here as quaizy said

#include <GUIConstants.au3>

GUICreate("Label disguised as a button"); will create a dialog box that when displayed is centered
Opt("GUIOnEventMode",1)
Dim $mylabel = GUICtrlCreateLabel ("Testing, one two three", 2, 2, 350,35, BitOR($BS_DEFPUSHBUTTON, $SS_SUNKEN, $BS_CENTER, $SS_LEFT), $SS_BLACKFRAME)
GUICtrlSetColor(-1,0x082BFE);blue
GUICtrlSetFont(-1,14,4,"","Arial")
GUICtrlSetBkColor(-1,0xF8FA6F); Yellow
GUICtrlSetOnEvent($mylabel, "_TestButton")
GUISetOnEvent(- 3, 'ExitNow')
GUISetState () ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    Sleep(10000)
Wend


Func _TestButton()
    $count = 1
    While _IsPressed('01')
        If $count = 1 Then
            GUICtrlSetColor($mylabel,0xF8FA6F);blue
            GUICtrlSetFont($mylabel,14,4,"","Arial")
            GUICtrlSetBkColor($mylabel,0x082BFE); Yellow
            $count = $count + 1
        EndIf
    WEnd
    GUICtrlSetColor($mylabel,0x082BFE);blue
    GUICtrlSetFont($mylabel,14,4,"","Arial")
    GUICtrlSetBkColor($mylabel,0xF8FA6F); Yellow
EndFunc

Func ExitNow()
    Exit
EndFunc

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

If you really want to use a colored button, might try looking at the example for GuiRegisterMsg in the beta

Is there any technical reason why the color of regular buttons cannot be changed? It seems like a lot of hassle to do something that (from the outside) seems pretty basic.

Also these proposed solutions do not really show the button being pressed, as with a regular button.

Angel

Edited by Angel
Link to comment
Share on other sites

Is there any technical reason why the color of regular buttons cannot be changed? It seems like a lot of hassle to do something that (from the outside) seems pretty basic.

Also these proposed solutions do not really show the button being pressed, as with a regular button.

Angel

I believe it has to do with how they are created

The example in GuiRegisterMsg is an ownerdrawn button and it does press like any regular button

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I believe it has to do with how they are created

The example in GuiRegisterMsg is an ownerdrawn button and it does press like any regular button

OK, I'll check it out. But this has been requested quite a few times. I'd be cool if it was allowed to change the colors of buttons as with the rest of regular GUI elemets...

Angel

Link to comment
Share on other sites

  • Moderators

Is there any technical reason why the color of regular buttons cannot be changed? It seems like a lot of hassle to do something that (from the outside) seems pretty basic.

Also these proposed solutions do not really show the button being pressed, as with a regular button.

Angel

The "proposed" suggestion that I gave showed it being pressed, but the proper way of doing this would be what gary said. Maybe you could edit that to change the color on press if you took a bit of time to try and play with the code. I'm on my way out but if I get some time later, I may try myself.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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