I wont to change the color of a button under runtime.
When I click on it it should change into red, when I click again back into the original color and so on.
Have no clou how to do that.
some help
Change color of button
Change color of button
OS X 10.10.5 PB 5.31(x64)
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Change color of button
You can do it with ButtonImageGadget(). Toggle button images with SetGadgetAttribute().
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Change color of button
For a single button:PowerSoft wrote:I wont to change the color of a button under runtime.
When I click on it it should change into red, when I click again back into the original color and so on.
Code: Select all
Procedure toggleButtonImage()
Shared btn, redButton, greenButton
Protected newState
If GetGadgetData(EventGadget()) = redButton
newState = greenButton
Else
newState = redButton
EndIf
SetGadgetData(btn, newState)
SetGadgetAttribute(btn, #PB_Button_Image, ImageID(newState))
EndProcedure
redButton = CreateImage(#PB_Any, 200, 50, 32, #Red)
greenButton = CreateImage(#PB_Any, 200, 50, 32, #Green)
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
win = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 400, 300,
"Toggle Button", wFlags)
btn = ButtonImageGadget(#PB_Any, 100, 120, 200, 50, ImageID(redButton))
SetGadgetData(btn, redButton)
BindGadgetEvent(btn, @toggleButtonImage())
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Code: Select all
Procedure toggleButtonImage()
Shared redButton, greenButton
Protected newState, btn = EventGadget()
If GetGadgetData(btn) = redButton
newState = greenButton
Else
newState = redButton
EndIf
SetGadgetData(btn, newState)
SetGadgetAttribute(btn, #PB_Button_Image, ImageID(newState))
EndProcedure
redButton = CreateImage(#PB_Any, 200, 50, 32, #Red)
greenButton = CreateImage(#PB_Any, 200, 50, 32, #Green)
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
win = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 400, 300,
"Toggle Image Buttons", wFlags)
btn1 = ButtonImageGadget(#PB_Any, 100, 50, 200, 50, ImageID(redButton))
btn2 = ButtonImageGadget(#PB_Any, 100, 120, 200, 50, ImageID(redButton))
btn3 = ButtonImageGadget(#PB_Any, 100, 190, 200, 50, ImageID(redButton))
SetGadgetData(btn1, redButton)
SetGadgetData(btn2, redButton)
SetGadgetData(btn3, redButton)
BindGadgetEvent(btn1, @toggleButtonImage())
BindGadgetEvent(btn2, @toggleButtonImage())
BindGadgetEvent(btn3, @toggleButtonImage())
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
- BasicallyPure
- Enthusiast
- Posts: 536
- Joined: Thu Mar 24, 2011 12:40 am
- Location: Iowa, USA
Re: Change color of button
Here is one with many options.
http://www.purebasic.fr/english/viewtop ... 12&t=51078
http://www.purebasic.fr/english/viewtop ... 12&t=51078
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
Until you know everything you know nothing, all you have is what you believe.