Jump to content

Button rollover - change pic


rCANE
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

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!"

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

Yashied,

You are quite correct. :)

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • 2 months later...

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