Changing the textcolor of RADIOS and CHECKB. at runtime ?

Changing the textcolor of RADIOS and CHECKB. at runtime ?

Postby ukoenig » Thu Jun 15, 2017 4:17 pm

Hello,

I wanted to change the textcolor of RADIOS and CHECKBOXES at runtime.
It only works on SAY

FUNCTION OBJ_UPDATE( oFld2, nTextColor, nBackColor )

// FOLDER

AEval( oFld2:aDialogs[ 2 ]:aControls, { |o| IF( o:ClassName == "TSAY", o:SetColor( nTextColor, nBackColor ), NIL ), ; // works !!!
IF( o:ClassName == "TRADIO", o:nClrText := nTextColor, NIL ), ;
IF( o:ClassName == "TCHECKBOX", o:SetColor( nTextColor, nBackColor ), NIL ), ;
o:Refresh() } )

// DIALOG

AEval( oDlgMain:aControls, { |o| IF( o:ClassName == "TSAY", o:SetColor( nTextColor, nBackColor ), NIL ), ; // works !!!
IF( o:ClassName == "TRADIO", o:nClrText := nTextColor, NIL ), ;
IF( o:ClassName == "TCHECKBOX", o:SetColor( nTextColor, nBackColor ), NIL ), ;
o:Refresh() } )

RETURN( NIL )


Test on DIALOG and FOLDER

Image

is it possible ( colorchange on button-action ) ?

The complete test
If You want to include it in the sample-collector
please delete this line in < SAMPLES.prg > function

// -------- FOLDER - Backgrounds ---------------
FUNCTION F_BACKGRD( oFld, lTransp )
...
...
// there is a fixed textcolor defined
AEval( oDlg:aControls, { |o| IF( o:ClassName == "TSAY", ( o:SetColor( 0, 13885951 ), o:Refresh() ), NIL ) } )

add to < CODE_2.prg > function < GRPC2_SEC2( oFld2, nSavePage ) >
delete the < NO SAMPLE > message


Code: Select all  Expand view  RUN

// ----------------------- GROUP 2 Page 2 -------------------------------------

FUNCTION GRPC2_SEC2( oFld2, nSavePage )
LOCAL oSay[4], nTextColor := 255, nBackColor := 3926784, oBtn1, oBtn2
LOCAL oRadio1, oRadio2, nRadio := 1, oCheck1, oCheck2, lCheck := .F.

//MsgAlert( "Folder-page 2 with GRADIENT", "Attention" )

@ 15, 30 SAY oSay[1] PROMPT " SAY - colortest " SIZE 240, 30 FONT oLarge OF oFld2:aDialogs[ 2 ] PIXEL  
oSay[1]:SetColor( nTextColor, nBackColor ) // Red text on Green

@ 55, 30 SAY oSay[2] PROMPT " SAY - transp.test " SIZE 250, 30 FONT oLarge OF oFld2:aDialogs[ 2 ] ;
PIXEL TRANSPARENT  
oSay[2]:SetColor( nTextColor, ) // Red text

@ 100, 30  RADIO oRadio1 VAR nRadio ITEMS "&One", "&Two", "T&hree" _3D SIZE 50, 12 ;
HELPID 100, 101, 102 OF oFld2:aDialogs[ 2 ] PIXEL UPDATE    
AEval( oRadio1:aItems, { | oRad | oRad:lTransparent := .T., ;
                              oRad:SetFont ( oMedium ), ;
                          oRad:nClrText := nTextColor } )

@ 100, 100 CHECKBOX oCheck1 VAR lCheck PROMPT " Checkbox" SIZE 70, 9 OF oFld2:aDialogs[ 2 ] FONT oMedium PIXEL  
oCheck1:SetColor( nTextColor, ) // Red text
oCheck1:lTransparent := .T.

// ------------- The DIALOG-area -------------

@ 440, 80 SAY oSay[3] PROMPT " SAY - colortest " SIZE 470, 60 FONT oLarge OF oDlgMain PIXEL  
oSay[3]:SetColor( nTextColor, nBackColor ) // Red text on Green

@ 520, 80 SAY oSay[4] PROMPT " SAY - transp.test " SIZE 480, 60 FONT oLarge OF oDlgMain ;
PIXEL TRANSPARENT  
oSay[4]:SetColor( nTextColor, ) // Red text

@ 590, 80  RADIO oRadio2 VAR nRadio ITEMS "&One", "&Two", "T&hree" _3D SIZE 70, 25 ;
HELPID 100, 101, 102 OF oDlgMain PIXEL UPDATE    
AEval( oRadio2:aItems, { | oRad | oRad:lTransparent := .T., ;
                              oRad:SetFont ( oMedium ), ;
                          oRad:nClrText := nTextColor } )

@ 595, 210 CHECKBOX oCheck2 VAR lCheck PROMPT " Checkbox" SIZE 120, 12 OF oDlgMain FONT oMedium PIXEL  
oCheck2:SetColor( nTextColor, ) // Red text
oCheck2:lTransparent := .T.

// -------------

@ 450, 670 BTNBMP oBtn1 OF oDlgMain ;
SIZE 120, 40 PIXEL 2007 ;
NOBORDER ;
PROMPT " &Text " ;
FILENAME c_Path1 + "PAINT.bmp" ;
ACTION ( nTextColor := ChooseColor(), ;
                OBJ_UPDATE( oFld2, nTextColor, nBackColor ) ) ;
FONT oSFont  ;
LEFT

@ 520, 670 BTNBMP oBtn2 OF oDlgMain ;
SIZE 120, 40 PIXEL 2007 ;
NOBORDER ;
PROMPT " &Backgrd. " ;
FILENAME c_Path1 + "PAINT.bmp" ;
ACTION ( nBackColor := ChooseColor(), ;
               OBJ_UPDATE( oFld2, nTextColor, nBackColor ) ) ;
FONT oSFont  ;
LEFT

RETURN NIL

// --------------

FUNCTION OBJ_UPDATE( oFld2, nTextColor, nBackColor )

AEval( oFld2:aDialogs[ 2 ]:aControls, { |o| IF( o:ClassName == "TSAY", o:SetColor( nTextColor, nBackColor ), NIL ), ;
                                                              IF( o:ClassName == "TRADIO", o:nClrText := nTextColor, NIL ), ;
                                                              IF( o:ClassName == "TCHECKBOX", o:SetColor( nTextColor, nBackColor ), NIL ), ;
                                      o:Refresh() } )

AEval( oDlgMain:aControls, { |o| IF( o:ClassName == "TSAY", o:SetColor( nTextColor, nBackColor ), NIL ), ;
                                                IF( o:ClassName == "TRADIO", o:nClrText := nTextColor, NIL ), ;
                                                IF( o:ClassName == "TCHECKBOX", o:SetColor( nTextColor, nBackColor ), NIL ), ;
                        o:Refresh() } )
SYSREFRESH()

RETURN( NIL )
 


regards
Uwe :?:
Last edited by ukoenig on Fri Jun 16, 2017 10:02 am, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Changing the textcolor of RADIOS and CHECKB. at runtime ?

Postby Rick Lipkin » Thu Jun 15, 2017 6:57 pm

Uwe

I use a separate field for check boxes and radio buttons .. just shorten the text to show control and create a text box to go along side .. that way ON CHANGE I can modify the text.

May not be very elegant, but it works.

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Changing the textcolor of RADIOS and CHECKB. at runtime ?

Postby ukoenig » Fri Jun 16, 2017 10:05 am

Rick,

I got it working changing the colors of RADIOS and CHECKBOXES as well with these changes :

// ---------------

FUNCTION OBJ_UPDATE( oFld2, nTextColor, nBackColor )

// ---FOLDER ---

AEval( oFld2:aDialogs[ 2 ]:aControls, { |o| IF( o:ClassName == "TSAY", ( o:SetColor( nTextColor, nBackColor ), o:Refresh() ), NIL ), ;
IF( o:ClassName == "TRADIO", ( o:nClrText := nTextColor, o:Refresh() ), NIL ), ;
IF( o:ClassName == "TCHECKBOX", ( o:SetColor( nTextColor, nBackColor ), o:Refresh() ), NIL ) } )

// --- DIALOG ---

AEval( oDlgMain:aControls, { |o| IF( o:ClassName == "TSAY", ( o:SetColor( nTextColor, nBackColor ), o:Refresh() ), NIL ), ;
IF( o:ClassName == "TRADIO", ( o:nClrText := nTextColor, o:Refresh() ), NIL ), ;
IF( o:ClassName == "TCHECKBOX", ( o:SetColor( nTextColor, nBackColor ), o:Refresh() ), NIL ) } )

Why needed ??? there is already a < o:Refresh() > that works with SAY

oDlgMain:Refresh()
oFld2:aDialogs[ 2 ]:Refresh()


RETURN( NIL )

// --------------

Image

regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 36 guests