Backcolor and fontcolor for labels do not show as expected

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
bluebird
Posts: 172
Joined: Wed Sep 28, 2016 3:55 am
DBs Used: DBF

Backcolor and fontcolor for labels do not show as expected

Post by bluebird »

HMG mentors

When I create a loop to make a matrix of labels, the background and font colors do not appear right away
when the labels are defined.
I had to create a additional loop to force the colors out. Does anyone know why.

In the code you will see a simple label called "color1" that works properly. However the matrix of labels seems to ignore
the color specs. Three matrix sets are called for, the first has the extra loop to illustrate.

Code: Select all



/*
* HMG General Test Routine
*
*/
#include "hmg.ch"
#define NEWLINE 13
#define DODGERBLUE {28,134,248}
#define LIGHTGOLDENROD {238 ,221 ,130 }
#define MAROON {238 ,48 ,100 }
#define COBALT1 {0,71,171}
#define COBALT2 {61,82,200}
#define ANTICOBALT1 {255-61,255-48,255-100}
#define TESTCOLOR {40,165,85}

* Set of define constants for gentest matrix draw demo
*
* 
*
#define ROW1 1
#define COL1 2
#define ROWSPC 3
#define COLSPC 4
#define CELLWIDTH 5
#define CELLHEIGHT 6
#define FONTSZ 7
#define BACKCOLOR1 8
#define FONTCOLOR1 9
#define TITLEROW 10
#define TITLEHEIGHT 11
#define CODEBLOCK1  12
#define WINFORM 13
#define LABELVALUE 14
#define LABELNAME 15
#define LOOPFUNCTNS 16
#define MTITLE 17
#define HDRFONTNAME 18
#define LABELFONTNAME 19
*------------------------------------------------------------*
Function Main
*------------------------------------------------------------*


  SET AUTOSCROLL ON
  DEFINE WINDOW Win_1 ;
    ROW 10 ;
    COL 10 ;
    WIDTH 750 ;
    HEIGHT 650 ;
    VIRTUAL WIDTH 1000 ;
    VIRTUAL HEIGHT 750 ;
    BACKCOLOR {12,130,55} ;
    TITLE 'A General Test Form!' ;
    WINDOWTYPE MAIN

  END WINDOW
  ON KEY Escape of Win_1               ACTION {||(Win_1.release)}


  Define BUTTON TestIt
  Parent win_1
  Row 650
  Col 25
  CAPTION "Click to Test Something"
  WIDTH 220
  Height 40 	
  ONCLICK  DoSomething()
  END BUTTON

  Define BUTTON TestAnother
  Parent win_1
  Row 650
  Col 290
  CAPTION "Click to Test Another"
  WIDTH 220
  Height 40 	
  ONCLICK DoSomethingElse()
  END BUTTON	



  Define Label Color11
  PARENT Win_1
  Row 500
  Col 510
  WIDTH 50
  HEIGHT 50
  FONTNAME "Ariel"
  ONCLICK NIL
  BACKCOLOR  COBALT1
  FONTCOLOR  ANTICOBALT1
  VALUE "COBALT"
  FONTSIZE 10
  End Label
  Win_1.Activate

Return


*------------------------------------------------------------*
Function DoSomething()
* Drawmatrix parameters index defined atop
* nRow1,nCol1,nRowSpc,nColSpc,nWidth,nHeight,nFontSz,aBackColor,aFontkColor,bOnCLick,
* cForm,bLabelValue,labelName,loopfunctions,MatrixTitle,hdr font,Label Font
*------------------------------------------------------------*
  Local nRows,nCols,cForm,cVaue,cn,J,K
  Local aMParameters:={},lSimpleVal:=.F.

  LOCAL b2:={|k,l|alltrim(str(k*l))}
  local b3:={|n|n}
  Local b4:={|m|m}
  LOCAL b5:={|lTrue,k,l,n|n:=iif(lTrue,k,l)}
  
* Define and set up parameters for Drawmatrix()
*
  Local cTitle:=" Demonstration of an Array of Labels "
  Local bLoopLogic:={|l,m|LoopFunctions(l,m,aMParameters)}
  Local bOnClickCode:={||(This.Value:=This.name)}

  Local bFirstVal2:={||' '}
  Local bFirstVal:={|k,l|alltrim(str(k*l))}
  PRIVATE cBlankInput:="-*-"

*=====================================================================
*Set Up parameters to call DrawMatrix()
*=====================================================================

  aMParameters:={10,10,2,2,25,20,9,{0,0,250},{240,240,0},4,20,bOnClickCode,"Win_1",;
    bFirstVal,"TLbl",bLoopLogic,cTitle,"Times New Roman","Arial"}  
  cForm:="Win_1";nRows:=8;nCols:=10

  DrawMatrix(nRows,nCols,aMParameters)


// *** Remove This loop  and the loop label colors are ingored
For j:= 1 to  nRows ;For k:=1 to ncols
    clabel :=aMParameters[LABELNAME]+ alltrim( str(j)) + alltrim(str(k) )
	setproperty("Win_1",clabel,"backcolor",COBALT2)
	NEXT k ; NEXT j

 
    aMParameters:={30,400,2,2,25,20,9,COBALT2,YELLOW,4,20,bOnClickCode,"Win_1",;
    bFirstVal2,"TLb2",bLoopLogic,NIL,"Times New Roman","Arial"}  
	DrawMatrix(nRows,nCols,aMParameters)
	
	aMParameters:={300,200,2,2,25,20,9,COBALT1,YELLOW,4,20,bOnClickCode,"Win_1",;
    bFirstVal2,"TLb3",bLoopLogic,NIL,"Times New Roman","Arial"}  
	DrawMatrix(nRows/2,nCols/2,aMParameters)
Return

*------------------------------------------------------------*
Function DrawMatrix(nRows,nCols,aMParameters )
*
* Draws a matrix of Cells - nRows X nCols
*
*Parameters list must be set up prior to call. Element names are
*Defined in MatrixHdr.ch.
*Elements WINFORM and LABELNAME are sting literals and require &'s
*Element CODEBLOCK1  is a code block for the ON CLICK procedure
*Element LABELVALUE  is a code block for the initial VALUE of the cells
*Element LOOPFUNCTNS is a code block to execute code specific to the loop
*Element MTITLE creates a Title Label unless it is set to NIL
*------------------------------------------------------------*
  Local j,k,clabel,cForm, cTitle


  cForm:=aMParameters[WINFORM]
  cTitle:=aMParameters[MTITLE]
  nTitleRow:=aMParameters[TITLEROW]
  nTitleHeight:=iif(cTitle!=NIL,aMParameters[TITLEHEIGHT],0)

  if cTitle != NIL
    Define Label cTitle
    PARENT &cForm
    Row aMParameters[TITLEROW]
    Col aMParameters[COL1]
    WIDTH (aMParameters[COLSPC]+aMParameters[CELLWIDTH])*nCols
    HEIGHT aMParameters[TITLEHEIGHT]
    FONTNAME aMParameters[HDRFONTNAME]              //"Ariel"
    ONCLICK {||This.backcolor:=DODGERBLUE}
    BACKCOLOR  aMParameters[BACKCOLOR1]             //aBackColor
    FONTCOLOR  aMParameters[FONTCOLOR1]
    VALUE cTitle
    FONTSIZE aMParameters[FONTSZ]*2
    End Label
  EndIf	

  for j:=1 to nRows
    for k := 1 TO nCols
      clabel :=aMParameters[LABELNAME]+ alltrim( str(j)) + alltrim(str(k) )

      // are there additional actions to take in the loop?	
      if aMParameters[LOOPFUNCTNS]!=Nil
        eval(aMParameters[LOOPFUNCTNS],j,k)
      endif

      DEFINE label &clabel
      PARENT &cForm
      VALUE eval(aMParameters[LABELVALUE],j,k)      //c1stVal
      Row max(nTitleHeight+aMParameters[TITLEROW],aMParameters[ROW1]);
        +2*aMParameters[ROWSPC]+(aMParameters[CELLHEIGHT]+aMParameters[ROWSPC])*(j-1)
      Col aMParameters[COL1]+(aMParameters[CELLWIDTH]+aMParameters[COLSPC])*(k-1)
      ON CLICK {||(eval (aMParameters[CODEBLOCK1]))}
      WIDTH aMParameters[CELLWIDTH]
      HEIGHT aMParameters[CELLHEIGHT]
      FONTNAME aMParameters[HDRFONTNAME]            //"Ariel"
      BACKCOLOR aMParameters[BACKCOLOR1]
      FONTCOLOR aMParameters[FONTCOLOR1]
      FONTSIZE aMParameters[FONTSZ]
      END LABEL
	  
	   if aMParameters[LOOPFUNCTNS]!=Nil
        eval(aMParameters[LOOPFUNCTNS],j,k)
      endif

    next k
   next j
    
Return Nil
*------------------------------------------
Function LoopFunctions(i,j,aMParameters)
*------------------------------------------
// nothing to do this loop

return

*------------------------------------------------------------*
Function DoSomethingElse()
*------------------------------------------------------------*
msgbox("nothing to do right now")
return


User avatar
serge_girard
Posts: 3167
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Backcolor and fontcolor for labels do not show as expected

Post by serge_girard »

Hi Bluebird,

In my opionon is is better to DEFINE all labels between DEFINE WINDOW and END WINDOW (at forehand), and then change properties ON CLICK.
Now it is really complicated to see what it must do (what is it supposed to do anyway, in the end?)

Serge
There's nothing you can do that can't be done...
User avatar
serge_girard
Posts: 3167
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Backcolor and fontcolor for labels do not show as expected

Post by serge_girard »

Also check your labels named

Code: Select all

TLB1 -->TLBL ( 1 # l ) 
Lowercase L looks like a number 1 in Courier New !
There's nothing you can do that can't be done...
User avatar
serge_girard
Posts: 3167
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Backcolor and fontcolor for labels do not show as expected

Post by serge_girard »

Also : DEFINE label &clabel in DrawMatrix
There's nothing you can do that can't be done...
User avatar
serge_girard
Posts: 3167
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Backcolor and fontcolor for labels do not show as expected

Post by serge_girard »

BB,
This codes should work as you designed it (+ re-edited for readability!!)
Changes: see 3 lines with //here

Code: Select all

/*
* HMG General Test Routine
*
*/
#include "hmg.ch"
#define NEWLINE 13
#define DODGERBLUE {28,134,248}
#define LIGHTGOLDENROD {238 ,221 ,130 }
#define MAROON {238 ,48 ,100 }
#define COBALT1 {0,71,171}
#define COBALT2 {61,82,200}
#define ANTICOBALT1 {255-61,255-48,255-100}
#define TESTCOLOR {40,165,85}

* Set of define constants for gentest matrix draw demo
*
* 
*
#define ROW1 1
#define COL1 2
#define ROWSPC 3
#define COLSPC 4
#define CELLWIDTH 5
#define CELLHEIGHT 6
#define FONTSZ 7
#define BACKCOLOR1 8
#define FONTCOLOR1 9
#define TITLEROW 10
#define TITLEHEIGHT 11
#define CODEBLOCK1  12
#define WINFORM 13
#define LABELVALUE 14
#define LABELNAME 15
#define LOOPFUNCTNS 16
#define MTITLE 17
#define HDRFONTNAME 18
#define LABELFONTNAME 19
*------------------------------------------------------------*
Function Main
*------------------------------------------------------------*


SET AUTOSCROLL ON
DEFINE WINDOW Win_1 ;
   ROW 10 ;
   COL 10 ;
   WIDTH 750 ;
   HEIGHT 650 ;
   VIRTUAL WIDTH 1000 ;
   VIRTUAL HEIGHT 750 ;
   BACKCOLOR {12,130,55} ;
   TITLE 'A General Test Form!' ;
   WINDOWTYPE MAIN

END WINDOW

  
  
ON KEY Escape of Win_1               ACTION {||(Win_1.release)}


Define BUTTON TestIt
   Parent win_1
   Row 650
   Col 25
   CAPTION "Click to Test Something"
   WIDTH 220
   Height 40 	
   ONCLICK  DoSomething()
END BUTTON

Define BUTTON TestAnother
   Parent win_1
   Row 650
   Col 290
   CAPTION "Click to Test Another"
   WIDTH 220
   Height 40 	
   ONCLICK DoSomethingElse()
END BUTTON	



Define Label Color11
   PARENT Win_1
   Row 500
   Col 510
   WIDTH 50
   HEIGHT 50
   FONTNAME "Ariel"
   ONCLICK NIL
   BACKCOLOR  COBALT1
   FONTCOLOR  ANTICOBALT1
   VALUE "COBALT"
   FONTSIZE 10
End Label
Win_1.Activate

Return




*------------------------------------------------------------*
Function DoSomething()
* Drawmatrix parameters index defined atop
* nRow1,nCol1,nRowSpc,nColSpc,nWidth,nHeight,nFontSz,aBackColor,aFontkColor,bOnCLick,
* cForm,bLabelValue,labelName,loopfunctions,MatrixTitle,hdr font,Label Font
*------------------------------------------------------------*
Local nRows,nCols,cForm,cVaue,cn,J,K
Local aMParameters:={},lSimpleVal:=.F.

LOCAL b2:={|k,l|alltrim(str(k*l))}
local b3:={|n|n}
Local b4:={|m|m}
LOCAL b5:={|lTrue,k,l,n|n:=iif(lTrue,k,l)}

* Define and set up parameters for Drawmatrix()
*
Local cTitle:=" Demonstration of an Array of Labels "
Local bLoopLogic:={|l,m|LoopFunctions(l,m,aMParameters)}
Local bOnClickCode:={||(This.Value:=This.name)}

Local bFirstVal2:={||' '}
Local bFirstVal:={|k,l|alltrim(str(k*l))}
PRIVATE cBlankInput:="-*-"

*=====================================================================
*Set Up parameters to call DrawMatrix()
*=====================================================================

aMParameters:={10,10,2,2,25,20,9,{0,0,250},{240,240,0},4,20,bOnClickCode,"Win_1",;
bFirstVal,"TLB1",bLoopLogic,cTitle,"Times New Roman","Arial"}  
cForm:="Win_1";nRows:=8;nCols:=10

DrawMatrix(nRows,nCols,aMParameters)


// *** Remove This loop  and the loop label colors are ingored
For j:= 1 to  nRows 
   For k:=1 to ncols
      clabel :=aMParameters[LABELNAME]+ alltrim( str(j)) + alltrim(str(k) )
	   setproperty("Win_1",clabel,"backcolor",COBALT2)
   nEXT k 
NEXT j

 
aMParameters:={30,400,2,2,25,20,9,COBALT2,YELLOW,4,20,bOnClickCode,"Win_1",  bFirstVal2,"TLB2",bLoopLogic,NIL,"Times New Roman","Arial"}  
DrawMatrix(nRows,nCols,aMParameters)

aMParameters:={300,200,2,2,25,20,9,COBALT1,YELLOW,4,20,bOnClickCode,"Win_1",  bFirstVal2,"TLB3",bLoopLogic,NIL,"Times New Roman","Arial"}  
DrawMatrix(nRows/2,nCols/2,aMParameters)
Return




*------------------------------------------------------------*
Function DrawMatrix(nRows,nCols,aMParameters )
*
* Draws a matrix of Cells - nRows X nCols
*
*Parameters list must be set up prior to call. Element names are
*Defined in MatrixHdr.ch.
*Elements WINFORM and LABELNAME are sting literals and require & s
*Element CODEBLOCK1  is a code block for the ON CLICK procedure
*Element LABELVALUE  is a code block for the initial VALUE of the cells
*Element LOOPFUNCTNS is a code block to execute code specific to the loop
*Element MTITLE creates a Title Label unless it is set to NIL
*------------------------------------------------------------*
Local j,k,clabel,cForm, cTitle


cForm:=aMParameters[WINFORM]
cTitle:=aMParameters[MTITLE]
nTitleRow:=aMParameters[TITLEROW]
nTitleHeight:=iif(cTitle!=NIL,aMParameters[TITLEHEIGHT],0)

if cTitle != NIL .AND. !IsControlDefined ( 'cTitle' , 'Win_1' )    //here
   Define Label cTitle
      PARENT &cForm
      Row aMParameters[TITLEROW]
      Col aMParameters[COL1]
      WIDTH (aMParameters[COLSPC]+aMParameters[CELLWIDTH])*nCols
      HEIGHT aMParameters[TITLEHEIGHT]
      FONTNAME aMParameters[HDRFONTNAME]              //"Ariel"
      ONCLICK {||This.backcolor:=DODGERBLUE}
      BACKCOLOR  aMParameters[BACKCOLOR1]             //aBackColor
      FONTCOLOR  aMParameters[FONTCOLOR1]
      VALUE cTitle
      FONTSIZE aMParameters[FONTSZ]*2
   End Label
EndIf	

for j:=1 to nRows
   for k := 1 TO nCols
      clabel := aMParameters[LABELNAME] + alltrim( str(j)) + alltrim(str(k) )
      // are there additional actions to take in the loop?	

      if aMParameters[LOOPFUNCTNS]!=Nil
         eval(aMParameters[LOOPFUNCTNS],j,k)
      endif

      if  !IsControlDefined ( &clabel , 'Win_1' )  // here

         DEFINE label &clabel   // here
            PARENT &cForm
            VALUE eval(aMParameters[LABELVALUE],j,k)      //c1stVal
            Row max(nTitleHeight+aMParameters[TITLEROW],aMParameters[ROW1]);
              +2*aMParameters[ROWSPC]+(aMParameters[CELLHEIGHT]+aMParameters[ROWSPC])*(j-1)
            Col aMParameters[COL1]+(aMParameters[CELLWIDTH]+aMParameters[COLSPC])*(k-1)
            ON CLICK {||(eval (aMParameters[CODEBLOCK1]))}
            WIDTH aMParameters[CELLWIDTH]
            HEIGHT aMParameters[CELLHEIGHT]
            FONTNAME aMParameters[HDRFONTNAME]            //"Ariel"
            BACKCOLOR aMParameters[BACKCOLOR1]
            FONTCOLOR aMParameters[FONTCOLOR1]
            FONTSIZE aMParameters[FONTSZ]
         END LABEL
	   ENDIF

	   if aMParameters[LOOPFUNCTNS]!=Nil
         eval(aMParameters[LOOPFUNCTNS],j,k)
      endif

   next k
next j
    
Return Nil



*------------------------------------------
Function LoopFunctions(i,j,aMParameters)
*------------------------------------------
// nothing to do this loop
return




*------------------------------------------------------------*
Function DoSomethingElse()
*------------------------------------------------------------*
msgbox("nothing to do right now")
return



There's nothing you can do that can't be done...
Post Reply