Method TSBrowse: SetColor()
Syntax:
oBrw:SetColor( <aElem>, <aColors> [,<nColumn>
] ) à oBrw
Description:
It assigns colors to all of the elements of the Browse (Cells, Headers,
Footers and Grid lines) individually for each column, or for all of them
included for specified cells.
Parameters:
aElem.- It is an Array of numbers
from 1 to 15, with any order, with which you indicate the elements of the
column(s) whose color(s) you want to assign.
You can use numbers, or the predefined constants in the file
TSBrowse.ch:
CLR_TEXT 1
// text of the cells
CLR_PANE 2
// background idem
CLR_HEADF 3
// text of the header
CLR_HEADB 4
// background idem
CLR_FOCUSF 5
// text of the cells with focus (cursor)
CLR_FOCUSB 6 //
background idem
CLR_EDITF 7 //
text of the cells when editing
CLR_EDITB 8 //
background idem
CLR_FOOTF 9
// text of the footer
CLR_FOOTB 10 //
background idem
CLR_SELEF 11 //
text of the cells with focus when browse is inactive
CLR_SELEB 12
// background idem
CLR_ORDF 13
// text of the controlling index column cells
CLR_ORDB 14
// background idem
CLR_LINE 15
// grid lines
aColors.- Is
an Array with the colors you want to assign to each element in the order
defined in aElem. They can
be variables with the numeric value of an RGB color mixture, or predefined
constants in the file Colors.ch (CLR_WHITE, CRL_RED, etc.), or as well Code
Blocks that when evaluated they return a value as above described.
NOTE: For a rectangled cursor ( Excel style
), the cursor background color (CLR_FOCUSB) must be expressed as a negative
number as follows:
-
1 = Rectangle in inversed color
-
2 = Rectangle in defined column text color
-
3 = Dotted rectangle
-
nColor = Rectangle in nColor ( could be any RGB negative color expression, eg. –CLR_RED
)
nColumn.- It
is the number of the column (Optional), to which you want to assign those
colors. If you omit this parameter, TSBrowse will assume that you want to
assign the colors to every column of the browse.
Returns: A reference to the same object modified.
Examples::
1.- Assign BLACK text color
on YELLOW background to the cells of the column 1:
oBrw:Setcolor( { 1, 2 }, { CLR_BLACK, CLR_YELLOW }, 1 )
2.- Assign WHITE text color
on BLACK background to the cells with focus (cursor) in all the columns:
oBrw:Setcolor( { CLR_FOCUSF, CLR_FOCUSB }, { CLR_WHITE, CLR_BLACK } )
3.- Assign BLACK text color
on GRAY background to the Headers of all columns:
oBrw:SetColor( { 3, 4 }, { CLR_BLACK, CLR_HGRAY } )
4.- Assign a variable
background color to the cells of browse (2) , and in the same time assign a
WHITE text color on GREEN background to the cursor (5,6), and GREEN grid lines
(15). For the variable color (2), we define a Code Block (marked with gray).
This assignment applies to every column because we omit the third parameter
(nColumn).
#define CLR_1 nRGB( 190, 215, 190 )
#define CLR_2 nRGB( 230, 230, 230 )
oBrw:SetColor( { 2, 5, 6, 15 }, { { | | If( OrdKeyNo() % 2 = 0, CLR_1,
CLR_2 ) }, CLR_WHITE, CLR_GREEN, CLR_GREEN }
)
Note: OrdKeyNo() is a Clipper 5.3 function that returns the position of
the record in the index, for the other RDD's you have to use the equivalent
function. Example: CmxKeyNo() for Comix, AX_KeyNo() for ADS,
sx_KeyNo(), For SixDriver. For DBFNTX
(Clipper 5.2x) does not exist an equivalent function, so you cannot use the
same Code Block, but you can always use the parameters passed by TSBrowse to
the color Code Blocks to evaluate them. Those parameters are: Position (::nAt),
Column (::nColPos),and the reference to the object it self (Self). In this way
you can use the following Code Block:
{ | Pos, Col, oBrw | If( Pos % 2 = 0, CLR_1, CLR_2 ) }. You can also use the oBrw:nLogicPos() method of TSBrowse, which supports
almosta every RDD. Example: { | | If( oBrw:nLogicPos() % 2 = 0, CLR_1, CLR_2 ) }
5.- You can assign text and
background colors at Cell level for one column only. Here we use two Code
Blocks, one to define the text color (1) (marked with gray) and the second to
define the background color (2) (marked in yellow), at cell level for only one
column. This assignment will apply only to the column 11 (third parameter).
oBrw:SetColor( { 1, 2 }, { { || If( Salary < 10001, CLR_WHITE, CLR_BLACK )
}, { || If( Salary
> 50000,CLR_HGREEN, ;
If( Salary > 10000,CLR_HRED,
CLR_RED ) ) } }, 11 )
6.- From Version 4.0 of TSBrowse, you can use degraded colors for background in cells, headers and footers. To do this, you have to define the background color in a 2 elements array with the following structure:
aBack := {
nClrFrom, nClrTo }
Where nClrFrom and nClrTo can be any valid color expression ( code
blocks included ).
oBrw:SetColor( { 1, 2 }, { CLR_BLACK, { CLR_WHITE, CLR_BLUE } } )
Or
oBrw:SetColor( { 1, 2 }, { CLR_BLACK, aBack } )
With this example cells background (2) will be painted in two colors
with a vertical gradient.
7.- Also from Version
4.0, you can use brushes as background color for cells, headers and footers:
DEFINE BRUSH oBrush RESOURCE “Back”
Obrw:SetColor( { 1, 2 }, { CLR_BLACK, oBrush } )
8.- New version
7.0 rectangled cursors
oBrw:SetColor( { 6 }, { -
CLR_RED } )