Sign in to follow this  
Followers 0
rCANE

Button rollover - change pic

8 posts in this topic

hi all!

i want a tiny rollover effect but i can't find how :)

so there is a button, no text just with a black and white ico pic.

when i move the mouse over change the pic (to the colored one) and when out change to it's original (black and white) pic.

thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can use MouseGetPos and compare the results with the known position of the button.

An easier way would be to use GUIGetCursorInfo. Take a look at the help file for GUIGetCursorInfo and you will find a return value for the button the mouse is over. Here is an example:

$GUI = GUICreate("GUI")
$Button = GUICtrlCreateButton("BUTTON", 50, 50)
GUISetState()

While 1
    $Msg = GUIGetCursorInfo($GUI)
    If $Msg[4] = $Button Then
        ConsoleWrite("ON BUTTON" & @CRLF)
        ;change the picture on the button
        While $Msg[4] = $Button
            $Msg = GUIGetCursorInfo($GUI)
            Sleep(50) ;ease up on the cpu
        WEnd
        ConsoleWrite("OFF BUTTON" & @CRLF)
    EndIf

    Sleep(50) ;ease up on the cpu
WEnd
Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

A method I use is to resize the image by a few pixels on mouseover and back to original size on mouseout.

Edit:

Another method is to create a copy of the original icon but slightly lighter or darker and then switch the image on mouseover.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

rCANE,

This works really nicely - but you need small BMPs rather than .ico files:

; Min Operating Systems: Windows XP

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

$hImage_1 = "BMP_1"
$hImage_2 = "BMP_2"

$hGUI = GUICreate("Button Imagelist - Test",400,300)

$hButton = GUICtrlCreateButton("", 30, 30, 32, 32)
GUICtrlSetTip(-1, "Multi state bitmap imagelist")
$hImage_Button = _GUIImageList_Create(24, 24, 5, 5)
_GUIImageList_AddBitmap($hImage_Button, $hImage_1)   ;1 - Normal
_GUIImageList_AddBitmap($hImage_Button, $hImage_2)   ;2 - Hot (ie cursor over)
_GUICtrlButton_SetImageList($hButton, $hImage_Button)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

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

Yashied,

You are quite correct. :)

My only excuse is that I copied that snippet from a working script which uses BMPs.

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
thank you guys, i'll try and screech when i have a problem. :)

Share this post


Link to post
Share on other sites

just to let you know i found this very usefull.

ive been using code to check where mouse pointer was and change the icon.

this is much better and reduced the complexity of the code i had to do.


We live as we dream alone!

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