topten

Using picture as a button problem

4 posts in this topic

I create  a picture as a button

$historyon = GUICtrlCreatePic("off.jpg", 280, 500, 30, 30)
GUICtrlSetState(-1, $GUI_DISABLE)
$ButtonNext = GUICtrlCreateLabel("", 280, 500, 30, 30)
 GUICtrlSetCursor(-1, 0)
 GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetState(-1, $GUI_ENABLE)
_GUICtrl_OnHoverRegister(-1, "_Hover_Proc", "_Leave_Hover_Proc", "PrimaryDown_Proc")

From the innitiate state the button on the gui is in "off" position. When the button is pressed the picture should be changed to "on" position

Later on I register the function for the button when it is pressed

Func PrimaryDown_Proc($historyon)
     local $buttonon, $buttonoff
    Switch $historyon
        Case $ButtonNext

        if $historyswitchedon=0 then
            $buttonon = GUICtrlCreatePic("on.jpg", 280, 500, 30, 30)
            GUICtrlDelete ($buttonoff)
;MsgBox (0, "", "0")
GUISetState()
$historyswitchedon=1
Return
        EndIf

        if $historyswitchedon=1 then
            $buttonoff = GUICtrlCreatePic("off.jpg", 280, 500, 30, 30)
            GUICtrlDelete ($buttonon)
;MsgBox (0, "", "1")
GUISetState()
$historyswitchedon=0
Return
EndIf
    EndSwitch

EndFunc

But I am getting not stable result: Sometimes, the picture of button is changed directly when I press on it, sometimes it is not changed, sometimes it is keeping changing from position "on" to position "off" while the button is being pressed several times. What am I doing wrong?

Share this post


Link to post
Share on other sites



Don't keep recreating the button, just use GUICtrlSetImage to change from one image to the other.

Also, if you need more help, please post a runnable script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@BrewManNH

I tried GUICTRLSETIMAGE but it seems not to work there

I guess I should have posted the question in this brunch

 

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

  • Similar Content

    • billthecreator
      By billthecreator
      I created a program that allows the user to create a countdown showing days, hours, minutes, and seconds left.

      The colors fade from dark to light. You may also change the color of each column, red, green, or blue. Or shades of grey.

      The program also uses MrCreatoR's

      If you choose not to use the hover effect, just remove the lines of code that uses it.

      It makes it much more stylish with it.



      Countdown.au3

      I made this because of Elder Scrolls V: Skyrim !