Jump to content

clicked button pic/image help


epicfail
 Share

Recommended Posts

How would i make it so if i have image buttons if 1 is clicked it stays the clicked pic and the other buttons turn to the unclicked pic and then when i click a different button the previouse button pic turnes to unclicked and the button just clicked turnes to clicked pic/image

Link to comment
Share on other sites

How would i make it so if i have image buttons if 1 is clicked it stays the clicked pic and the other buttons turn to the unclicked pic and then when i click a different button the previouse button pic turnes to unclicked and the button just clicked turnes to clicked pic/image

Keep all the related buttons IDs in an array. The function that handles your button clicks just loops once through the array and changes the pics:
For $n = 0 to UBound($avButtons) - 1
    If $avButtons[$n] = $iClickedButtonID Then
        GUICtrlSetImage($avButtons[$n], $sClickedImage)
    Else
        GUICtrlSetImage($avButtons[$n], $sUnclickedImage)
    EndIf
Next

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Haven't tested it, but you might be able to set up a 2d array like this:

$array[$buttonid][$piclocation]

Edit: Or you might be able to just have a 1d array where all odd values are buttons and all even values are pics, and use a for loop with step 2, and then to get the pic you just do $n - or + 1

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

im confused. how would i get it to work with this script.

#include <GUIConstantsEx.au3>
#include <GUICtrlSetOnHover_UDF.au3>
;

Global $PlayIsClicked   = False
Global $sImages_Path    = @ScriptDir & "\Example Images"

$Gui = GUICreate("onclick Hovering Example", 280, 200)
GUISetBkColor(0xFFFFFF)

$Button = GUICtrlCreatePic($sImages_Path & "\Button.jpg", 82, 24, 82, 24)
_GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")

$Round = GUICtrlCreatePic($sImages_Path & "\Round_Button.jpg", 82, 70, 150, 24)
_GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")

$Pause = GUICtrlCreatePic($sImages_Path & "\Pause_Button.jpg", 110, 100, 40, 40)
_GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")

$Play = GUICtrlCreatePic($sImages_Path & "\Play_Button.jpg", 70, 100, 40, 40)
_GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc", "PrimaryUp_Proc")

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    
    ;We use Global variable and main loop to avoid the blocking of OnHover function (please read UDF docs)
    If $PlayIsClicked Then
        $PlayIsClicked = False
        
        MsgBox(64, "", "You Clicked 'Play' Button")
    EndIf
WEnd

Func _Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Button_Hover.jpg")
        Case $Round
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Round_Button_Hover.jpg")
        Case $Pause
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Pause_Button_Hover.jpg")
        Case $Play
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Play_Button_Hover.jpg")
    EndSwitch
EndFunc

Func _Leave_Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Button.jpg")
        Case $Round
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Round_Button.jpg")
        Case $Pause
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Pause_Button.jpg")
        Case $Play
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Play_Button.jpg")
    EndSwitch
EndFunc

Func PrimaryDown_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Button_Click.jpg")
        Case $Round 
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Round_Button_Click.jpg")
        Case $Pause
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Pause_Button_Click.jpg")
        Case $Play
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Play_Button_Click.jpg")
            
            ;$PlayIsClicked = True
    EndSwitch
EndFunc

Func PrimaryUp_Proc($iCtrlID)
    Switch $iCtrlID
        Case $Button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Button_Hover.jpg")
        Case $Round 
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Round_Button_Hover.jpg")
        Case $Pause
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Pause_Button_Hover.jpg")
        Case $Play
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Play_Button_Hover.jpg")
            
            $PlayIsClicked = True
    EndSwitch
EndFunc

PrimaryDown_Proc is the clicked button so how would i make it so it stays as that till u click another button?

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