colored button
Posted: Fri Sep 02, 2016 8:49 pm
I a'm new to PB.I have a problem with colored buttons.
I found this example and I try to change it,the buttons gets the wanted color ,but when toggled the text is invissible
__________________________________________________
Code tags added
02.09.2016
RSBasic
I found this example and I try to change it,the buttons gets the wanted color ,but when toggled the text is invissible
Code: Select all
;COLORED button
;needed :when selected background and textcolor must change
;PROBLEM : background change but text is invissible ???
EnableExplicit
Define text ;textcolor button
Define back ;backgroundcolor button
Define mywin,ev,width,height,x,y
Declare SetButtonColor(hGadget, text, back) ;procedure declaration
mywin= OpenWindow (0,0,0,500,468, "color button" , #PB_Window_SystemMenu|#PB_Window_ScreenCentered )
If mywin
ButtonGadget(1, 10, 10, 250, 60, "Button 1")
back=RGB(255,0,0) ;back=red
text=RGB(0,255,0) ;text=green
SetButtonColor(1, text, back) ;call procedure
ButtonGadget(2, 10, 100, 250, 60, "Button 2") ; button 2
back=RGB(255,0,0) ;back=red
text=RGB(0,255,0) ; text=green
SetButtonColor(2, text, back) ;call procedure with desired colors
Repeat
ev=WaitWindowEvent ()
Select ev
Case #PB_Event_Gadget
Select EventGadget()
Case 1: back=RGB(255,0,0)
text=RGB(0,0,255) ;change textcolor when pressed
SetButtonColor(1, text,back) ;if button1 pressed change color to blue text
Case 2: back=RGB(255,255,0) ;change to yellow
text=RGB(0,0,255)
SetButtonColor(2, text,back);if button2 pressed change color to blue text
EndSelect
EndSelect
Until ev= #PB_Event_CloseWindow
EndIf
;---------------------------------------------------------------------------------------------------------
Procedure SetButtonColor(Id, text, back)
Define txt.s
Define width.I,height.i,x.i,y.i,result.i
Txt.s=GetGadgetText(Id)
width=GadgetWidth(Id)
Height=GadgetHeight(Id)
x=GadgetX(Id)
y=GadgetY(Id)
FreeGadget(Id)
If IsFont(Id)
FreeFont(Id)
EndIf
If IsImage(Id)
FreeImage(Id)
EndIf
LoadFont(Id, "Arial 24", 18, #PB_Font_Bold)
If CreateImage(Id, width, height)
StartDrawing(ImageOutput(Id))
DrawingMode(#PB_2DDrawing_Transparent)
Box(0, 0,width, height, back)
DrawingFont(FontID(Id))
FrontColor(text)
DrawText((width-TextWidth(txt))/2,(height-TextHeight(txt))/2,Txt.s)
StopDrawing()
EndIf
ButtonImageGadget(Id,x,y,width,Height,ImageID( Id))
ProcedureReturn result
EndProcedure
Code tags added
02.09.2016
RSBasic