Sign in to follow this  
Followers 0
sensalim

Change label when mouse hovers certain button?

10 posts in this topic

I have 5 buttons and 1 label.

How do I do it so that when the mouse hovers on button1, label would say "Button #1" etc.

?

Thanks!

Share this post


Link to post
Share on other sites



GUIGetCursorInfo

GUICtrlSetData


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.

Share this post


Link to post
Share on other sites

Something like this in your while loop:

While 1
    $mouse = GUIGetCursorInfo ()
    Select
        Case $mouse[4] = $button1
            GUICtrlSetData ($label1, "Hovering on Button 1")
    EndSelect
WEnd

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks all.

Bert, that loop makes flickers... lots of flickers on that label.

How do I reduce the flickers... sleep()?

Edit:

I added sleep(100) - no more flickers but response level is not acceptable.

I changed it to sleep(50) and things look great. Anything wrong with sleep(50) or 100?

Edited by sensalim

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks all.

Bert, that loop makes flickers... lots of flickers on that label.

How do I reduce the flickers... sleep()?

Edit:

I added sleep(100) - no more flickers but response level is not acceptable.

I changed it to sleep(50) and things look great. Anything wrong with sleep(50) or 100?

Probably a more efficient way of dealing with it is recording what the mouse if over and then checking that when also. Then if the mouse is over the same control as it was last time it won't set the data... I'll post an example in a second

GuiCreate('Testing Beep', 400, 40)

$btnStart = GuiCtrlCreateButton('Start', 5, 5, 185, 30)

$btnStop = GuiCtrlCreateButton('Stop', 205, 5, 185, 30)

$lastHovered = -1

GuiSetState()

While 1
    $mouse = GUIGetCursorInfo ()
    Select
        Case $mouse[4] = $btnStart
            If $lastHovered <> $btnStart then 
                GUICtrlSetData ($btnStart, "Start HOVER")
            EndIf
            $lastHovered = $btnStart
        Case $mouse[4] = $btnStop 
            If $lastHovered <> $btnStop then 
                GUICtrlSetData ($btnStop, "Stop HOVER")
            EndIf       
            $lastHovered = $btnStop
        Case Else 
            If $lastHovered = $btnStart and GuiCtrlRead($btnStart) = 'Start HOVER' then 
                GUICtrlSetData ($btnStart, "Start")
                $lastHovered = -1
            ElseIf $lastHovered = $btnStop and GuiCtrlRead($btnStop) = 'Stop HOVER' then
                GUICtrlSetData ($btnStop, "Stop")
                $lastHovered = -1
            ENdIf
    EndSelect
    
    Switch GuiGetMsg() 
        Case -3 
            Exit 
            
    EndSwitch
WEnd
Edited by Piano_Man

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hm I'm getting an error after assigning a function to button1, saying mouse is not an array...

Edit:

I realize that my script is using

Opt("GUIOnEventMode", 1)

and that does not work well... how do I do it with this option?

or another way to do this...

Thanks!

Edited by sensalim

Share this post


Link to post
Share on other sites

Hm I'm getting an error after assigning a function to button1, saying mouse is not an array...

Edit:

I realize that my script is using

Opt("GUIOnEventMode", 1)

and that does not work well... how do I do it with this option?

or another way to do this...

Thanks!

A little effort on your part would be ... well... GREAT!!!

How about you make us an example GUI to work with so we don't have to waste any of our time serving your request?


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.

Share this post


Link to post
Share on other sites

hi,

Event mode 1 example using minimal cpu and crisp response when hovering.

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

Global $But[6], $bX = 5, $Last

$Gui = GUICreate(":-)", 330, 55)
$Lbl = GUICtrlCreateLabel("", 5, 5, 320, 15, $SS_CENTER)
For $i = 1 To 5
    $But[$i] = GUICtrlCreateButton("Button " & $i, $bX, 25, 60, 20)
    $bX += 65
Next
GUISetOnEvent($GUI_EVENT_CLOSE, "Close", $Gui)
GUISetState(@SW_SHOW, $Gui)

While 1
    Sleep(10)
    Hover()
WEnd

Func Hover()
    $GGCI = GUIGetCursorInfo($Gui)
    If $GGCI[4] <> $Last Then
        GUICtrlSetData($Lbl, _Data($GGCI[4]))
        $Last = $GGCI[4]
    EndIf
EndFunc 

Func _Data($cID)
    For $i = 1 To 5
        If $cID = $But[$i] Then Return "Button " & $i
    Next
    Return ""
EndFunc

Func Close()
    Exit
EndFunc

Cheers

1 person likes this

Share this post


Link to post
Share on other sites

Thanks all. It works now, smashly - except I have to add another global array for the button description, because they aren't just

"Button 1" ... "Button 5"

That ok right?

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