Problem changing a buttons text

Get help with using AutoHotkey and its commands and hotkeys
braunbaer
Posts: 180
Joined: 22 Feb 2016, 10:49

Problem changing a buttons text

25 Dec 2020, 21:30

I have created a GUI with a button, which should display "remove from favorites" when a page is already a favorite, and "add to favorites" when a page is not yet a favorite.

There is a small routine which should set the caption of the button according to the variable FavIndex

Code: Select all

setFavTitle:
s:=FavIndex?"remove from favorites":"add to favorites"
GuiControl,,saffFav,%s%   
debug("GUIControl s=" . s, A_Linenumber) ; writes debug output to a file to verify if s is correct
return
When I create the GUI

Code: Select all

gui add,button,gsaffzeigen w100,xxx
gosub SetFavTitle
the procedure Set FavTitle works fine, the button displays the correct title (and not "xxx"), depending on the value of Favindex.


But every second, I call a timer routine whicks checks if something has changed:

Code: Select all

safftimer: 
...
FavIndex:=0
for ind, s in FavURLs
    if (saffUrl=s)    ; saffurl always contains the url of the currently displayed page 
	   {
           FavIndex:=ind 
           break
           }
gosub SetFavTitle	
exit         ; exit the timer routine
and in that case, the display of the button does not change, although the debug output in setfavtitle shows that the correct string value for the title is passed to the command GuiControl.

Is it necessary to make another command to display the button again?
User avatar
Xtra
Posts: 2060
Joined: 02 Oct 2015, 12:15

Re: Problem changing a buttons text

26 Dec 2020, 01:25

Try:

Code: Select all

; Create button:
gui add,button,gsaffzeigen vsaffFav w100,xxx

; Change button:
GuiControl,,saffFav,%s%

Return to “Ask For Help”

Who is online

Users browsing this forum: ark, Bing [Bot], LC99, mikeyww, Spawnova and 35 guests