Page 1 of 1
Why doesn't SetGadgetState work properly with ImageGadget?
Posted: Sat Oct 21, 2006 6:28 am
by paleozord
In the manual it states:
Code: Select all
- SetGadgetState(): Change the current Image of the gadget. A valid ImageID can be easily obtained with the UseImage() or ImageID() commands. If the ImageID is 0, then the image is removed from the gadget.
But if I have an image currently displayed in a ImageGadget (#Image_0) from whatever source (it doesn't matter), and I try:
It does not remove the currently displayed image from the gadget at all, as it states in the manual. Instead nothing happens and the image is left intact and displayed, as before.
Why doesn't specifying zero as the ImageID remove the image from the gadget, as the manual states it should? Thanks!
Re: Why doesn't SetGadgetState work properly with ImageGadge
Posted: Sat Oct 21, 2006 7:49 am
by PB
Here's an example that shows how to do it, and proves the manual is correct:
Code: Select all
If OpenWindow(0,300,200,300,200,"test",#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
pic1=CreateImage(1,50,50) ; Small black square.
pic2=CreateImage(2,100,100) ; Large black square.
ImageGadget(1,20,20,100,100,pic1)
ButtonGadget(2,20,130,130,25,"Click to switch images")
Repeat
ev=WaitWindowEvent()
If ev=#PB_Event_Gadget And EventGadget()=2
count+1
If count=1
SetGadgetState(1,pic2)
SetGadgetText(2,"Click to clear image")
ElseIf count=2
SetGadgetState(1,0)
EndIf
EndIf
Until ev=#PB_Event_CloseWindow
EndIf
Posted: Sat Oct 21, 2006 5:48 pm
by paleozord
Hi, thanks for your reply and help with the example. However, when I run that code in PB (after fixing the minor error in the OpenWindow statement that prevented it from running) I can confirm that clicking the button the second time does NOT remove/clear the "large black square" image from the gadget. Instead the image just stays there forever, until the program is terminated.
I am running PB4 on Windows XP (SP2). What am I doing wrong? Does it actually blank out the larger square for you, when you click the button the second time?
Posted: Sat Oct 21, 2006 5:53 pm
by nco2k
@paleozord
are you using SmartWindowRefresh()? it has some problems with images/icons
http://www.purebasic.fr/english/viewtopic.php?t=24195 i hope this will be fixed soon.
c ya,
nco2k
Posted: Sat Oct 21, 2006 6:01 pm
by paleozord
Hi.. no I haven't deliberately enabled SmartWindowRefresh, just running PB the default way with no such special command. But even when I deliberately did:
... it made no difference. Same result, large black square doesn't go away on second button click.
Posted: Sat Oct 21, 2006 6:03 pm
by nco2k
download the latest beta image lib from
http://www.purebasic.com/beta/ install it and restart the compiler.
c ya,
nco2k
Posted: Sat Oct 21, 2006 6:16 pm
by paleozord
I downloaded the newest image lib, copied-and-pasted it over my old version in PureLibraries, restarted the compiler but no difference. Large black square still isn't cleared with second button click.
Posted: Sat Oct 21, 2006 6:23 pm
by nco2k
hm.. try the beta gadget lib aswell, because its a gadget after all. if that doesnt work i really dont know why it doesnt work for you properly.
have you installed pb4 into a new empty folder or over an existing older pb version?
c ya,
nco2k
Posted: Sat Oct 21, 2006 6:36 pm
by paleozord
nco2k wrote:hm.. try the beta gadget lib aswell, because its a gadget after all. if that doesnt work i really dont know why it doesnt work for you properly.
have you installed pb4 into a new empty folder or over an existing older pb version?
Tried the newest gadget lib but no luck there either. I installed PB4 into a new
empty folder. I still have my older version (3.9x) intact in its old folder.
It's quite a mystery why it isn't working for me, and I guess there's nothing to do about it for the time being. Thank you for the help though really, I do appreciate the attempt.
Posted: Sat Oct 21, 2006 8:03 pm
by rsts
PB's example works fine for me right out of the page - no window error anything.
small box
larger box
clear
don't know what it might be.
I'm PB 4 final with no beta libs.
cheers
Posted: Sat Oct 21, 2006 8:47 pm
by paleozord
Okay, I re-installed PB4 completely and now it does in fact seem to work fine. I'm not sure why this was happening, but I think the compiler was still referencing some of my older 3.9x files in the old directory, as evidenced by the fact that the initially posted code produced an old-time error on the OpenWindow statement, wanting the text name of the window to come after the flags, as it used to be in older versions of PB.
Anyway, thanks again to all for the help.. off I go to make some more progress....
Posted: Sun Oct 22, 2006 12:50 am
by PB
Yes, you should always install new versions into their own folder.