[Lazarus] Colouring StringGrids
Héctor Fiandor Rosario
hfiandor at infomed.sld.cu
Tue Jul 15 13:59:21 CEST 2008
Dear Mr. Dave:
I am a new one in FP but I have some years in Delphi.
for coloring stringgrid´cells I use the following routine:
procedure TfBasica829.StringGrid2PrepareCanvas(sender: TObject; aCol,
aRow: Integer; aState: TGridDrawState);
var
aTextStyle: TTextStyle;
begin
{
clRed, clGreen, clYellow, clBlue,
clWhite, clGray, clFuchsia, clTeal,
clNavy, clMaroon, clLime, clOlive,
clPurple, clSilver, clAqua, clBlack
}
if (ACol=0) then //1
begin
Stringgrid2.Canvas.Brush.Color := clRed; //
aTextStyle := StringGrid2.Canvas.TextStyle;
aTextStyle.Alignment:=taCenter; //taRightJustify;
aTextStyle.Layout:=tlCenter; //tlBottom;
StringGrid2.Canvas.TextStyle := aTextStyle;
end
else
if ACol=1 then //1.5
begin
Stringgrid2.Canvas.Brush.Color := clOlive{Green}; //
aTextStyle := StringGrid2.Canvas.TextStyle;
aTextStyle.Alignment:=taCenter; //taRightJustify;
aTextStyle.Layout:=tlCenter; //tlBottom;
StringGrid2.Canvas.TextStyle := aTextStyle;
end
else
if ACol=2 then //2
begin
Stringgrid2.Canvas.Brush.Color := clYellow; //
aTextStyle := StringGrid2.Canvas.TextStyle;
aTextStyle.Alignment:=taCenter; //taRightJustify;
aTextStyle.Layout:=tlCenter; //tlBottom;
StringGrid2.Canvas.TextStyle := aTextStyle;
end
else
if ACol=3 then //2.5
begin
Stringgrid2.Canvas.Brush.Color := clAqua; //
aTextStyle := StringGrid2.Canvas.TextStyle;
aTextStyle.Alignment:=taCenter; //taRightJustify;
aTextStyle.Layout:=tlCenter; //tlBottom;
StringGrid2.Canvas.TextStyle := aTextStyle;
end
else
if ACol=4 then //3.0
begin
Stringgrid2.Canvas.Brush.Color := clSilver; //
aTextStyle := StringGrid2.Canvas.TextStyle;
aTextStyle.Alignment:=taCenter; //taRightJustify;
aTextStyle.Layout:=tlCenter; //tlBottom;
StringGrid2.Canvas.TextStyle := aTextStyle;
end;
end;
to obtain this
maybe this can help you.
bye,
Ing. Héctor F. Fiandor
hfiandor at infomed.sld.cu
----- Original Message -----
From: "Dave Coventry" <dgcoventry at gmail.com>
To: "General mailing list" <lazarus at lazarus.freepascal.org>
Sent: Tuesday, July 15, 2008 7:15 AM
Subject: [Lazarus] Colouring StringGrids
> Hi,
>
> I'm using the following code to (unsuccessfully) colour the fields of
> a row in a tstringgrid if the second column is empty.
>
> if StringGrid2.Cells[1,i]='' then
> begin
> PriceHeader:=true;
> StringGrid2.Repaint;
> end;
>
>
> procedure TForm1.StringGrid2DrawCell(Sender: TObject; aCol, aRow: Integer;
> aRect: TRect; aState: TGridDrawState);
> var oldColour:TColor;
> oldBrush: TBrush;
> begin
> with StringGrid2 do
> begin
> if PriceHeader then
> begin
> oldcolour:=font.Color;
> oldBrush:=Canvas.Brush;
> Brush.Color:=clNavy;
> font.Color:=clWhite;
> Canvas.FillRect(aRect);
> font.Color:=oldColour;
> Canvas.Brush:=oldBrush;
> PriceHeader:=false;
> end;
> end;
> end;
>
> Can anyone give me a clue as to why it's not working?
> _______________________________________________
> Lazarus mailing list
> Lazarus at lazarus.freepascal.org
> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
>
> __________ Información de ESET Smart Security, versión de la base de firmas de virus 3268 (20080715) __________
>
> ESET Smart Security ha comprobado este mensaje.
> http://www.eset.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20080715/7fcec315/attachment-0007.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: snap.jpg
Type: image/jpeg
Size: 17209 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20080715/7fcec315/attachment-0002.jpg>
More information about the Lazarus
mailing list