 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jorge Ferreira Guest
|
Posted: Tue Oct 07, 2003 11:44 am Post subject: Coloured Grids |
|
|
Hi Experts,
How can i put different font colors in my grid (StringGrid or DBGrid).
The goal is that i want that everytime that i'm going to fill my cell
in the grid with an negative value in the first column, i want that
the font for all the row becomes red. How can i do this?
Thank you in advance for any help or ideas,
Jorge Ferreira
|
|
| Back to top |
|
 |
Bruce Roberts Guest
|
Posted: Tue Oct 07, 2003 6:49 pm Post subject: Re: Coloured Grids |
|
|
"Jorge Ferreira" <jorge.ferreira (AT) lycos (DOT) co.uk> wrote
| Quote: | How can i put different font colors in my grid (StringGrid or DBGrid).
The goal is that i want that everytime that i'm going to fill my cell
in the grid with an negative value in the first column, i want that
the font for all the row becomes red. How can i do this?
|
You need to make it OwnerDraw and supply code to paint each cell.
|
|
| Back to top |
|
 |
Christakis John Guest
|
Posted: Thu Oct 09, 2003 1:44 pm Post subject: Re: Coloured Grids |
|
|
Hiya,
This is how I did it. When the stringgrid was being populated I put a
colour number into the Objects array. So Negative numbers were set to red
and all others were set to black.
But one of the grids (Grid1) I wanted to colour the entire Cell instead of
the text, so the IF selects whether we are changing the Brush colour or the
Font colour.
Note that this event fires for every cell in the grid, so you have to tell
it what to do with the fixed cells and the highlighted cell - notice their
are using clBtnFace, clHighlight etc etc. You can adjust to suit.
Notice that if you are fiddling with the brush colour, you may need to
update every Cell Object, as the default value is 0.
enjoy,
cj
procedure TfrmMain.StringGrid_onDrawCell(Sender: TObject; ACol, ARow:
Integer; Rect: TRect; State: TGridDrawState);
const
LM = 3; // each indiviual cell's left margin
TM = 2; // each indiviual cell's top margin
var
ptr: Pointer;
begin
// use whatever color is stored in the object's pointer
ptr := (Sender as TStringGrid).Objects[ACol, ARow];
// Use Canvas.Font to change words and Canvas.Brush to change background
if (Sender as TStringGrid).Name='Grid1' then
(Sender as TStringGrid).Canvas.Brush.Color := LongInt(ptr)
else
(Sender as TStringGrid).Canvas.Font.Color := LongInt(ptr);
// let'd draw the fixed rows and the fixed columns in silver
if gdFixed in State then
(Sender as TStringGrid).Canvas.Brush.Color := clBtnFace;
// let's draw the highlight in the following way when the cell is
selected
if gdSelected in State then begin
(Sender as TStringGrid).Canvas.Brush.Color := clHighlight;
(Sender as TStringGrid).Canvas.Font.Color := clHighlightText;
end;
// finally, do the actual cell drawing}
(Sender as TStringGrid).Canvas.TextRect(Rect, Rect.Left + LM, Rect.Top +
TM, (Sender as TStringGrid).Cells[Acol,Arow]);
end;
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|