Jump to content
Sign in to follow this  
3lbuniverse

Mouse movement and button colors

Recommended Posts

3lbuniverse

Hello there! Moving the mouse over a button changes it to blue, so how do I change the color it changes the button to? Can I get it to change the color of a button with a background color already set? Thanks for your help.

Share this post


Link to post
Share on other sites
picea892

Please provide code. If you have a code that changes a button to blue on mouseover it would be extremely simple to change the colour it changes to.

Share this post


Link to post
Share on other sites
3lbuniverse

Thats the thing, when I move the mouse over the button, it just turns blue by itself. I didn't do anything and can't find any code to control the change at all. And when I color the button with a GUICtrlSetBkColor($btn,0xffe4b5), then it doesn't change color at all.

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <GuiButton.au3>

GUICreate("Buttons", 510, 400)

$btn = GUICtrlCreateButton("Button", 10, 10, 90, 50)

GUISetState(@SW_SHOW)

While 1

$msg= GUIGetMsg()

Select

Case $msg=$GUI_EVENT_CLOSE

ExitLoop

EndSelect

WEnd

Share this post


Link to post
Share on other sites
Mat

I think that Custom drawing the control would do it, but unless you know what your doing it's probably not what you want to do. That colour is decided by the windows theme (I presume you are running vista, as thats the effect I get)

Share this post


Link to post
Share on other sites
3lbuniverse

So, its a windows thing, not an autoit thing? I figured I might be dealing with some internal function that I couldn't bend to my will. I'm not sure what you mean by Custom drawing the control but I'm interested in learning more, especially if it's an alternative to the _ButtonHover. Any other approaches to controling the color of a button when the mouse is over it? Thanks!

Share this post


Link to post
Share on other sites
3lbuniverse

I got it! First I was making it too simple by hoping I could control what Mat pointed out was a windows vista theme, then I was was making it too complex trying to use new UDFs, though those buttons do look pretty cool picea892. I thought it had to be possible using simple GUIGetCursorInfo but I kept getting this flickering, so combing through this forum, Melba23 provided a perfect soultion with a flag to prevent the flickering. Works great, thank you all!

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <GuiButton.au3>

$Green=0x00FF00

$Red=0xFF0000

GUICreate("Buttons", 510, 400)

$btn = GUICtrlCreateButton("Button", 10, 10, 90, 50)

GUICtrlSetBkColor($btn, $Red)

$fLabel = "Red"

GUISetState(@SW_SHOW)

While 1

$msg= GUIGetMsg()

$a = GUIGetCursorInfo()

Select

Case $msg=$GUI_EVENT_CLOSE

ExitLoop

EndSelect

If $a[4] = $btn And $fLabel = "Red" Then

GUICtrlSetBkColor($btn, $Green)

$fLabel = "Green"

ElseIf $a[4] <> $btn And $fLabel = "Green" Then

GUICtrlSetBkColor($btn, $Red)

$fLabel = "Red"

EndIf

WEnd

Share this post


Link to post
Share on other sites
Melba23

3lbuniverse,

Delighted I could help without actually being there - so to speak! :

A couple of points:

1. When you colour your buttons they trap "Enter" - i.e. whenever you press the "Enter" key, it is as though you pressed the button. It is a known bug and too deeply embedded in AutoIt for it to be changed. There is no reason not to colour buttons - but you need to be aware of this behaviour or it can get a bit confusing when the script apparently happens to fire off events on its own! Here is your code with a small addition - try pressing "Enter" and see what happens :huggles: :

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

$Green = 0x00FF00
$Red = 0xFF0000

GUICreate("Buttons", 510, 400)

$btn = GUICtrlCreateButton("Button", 10, 10, 90, 50)
GUICtrlSetBkColor($btn, $Red)

$fLabel = "Red"

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    $a = GUIGetCursorInfo()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $btn
            MsgBox(0, "Button", "Did you click the button" & @CRLF & "Or press Enter?")
    EndSelect

    If $a[4] = $btn And $fLabel = "Red" Then
        GUICtrlSetBkColor($btn, $Green)
        $fLabel = "Green"
    ElseIf $a[4] <> $btn And $fLabel = "Green" Then
        GUICtrlSetBkColor($btn, $Red)
        $fLabel = "Red"
    EndIf

WEnd

2. When you post code, it makes it much easier to read if you use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). :D

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
3lbuniverse

I see what you mean about it pressing enter, thats interesting. Thanks for the tips!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.