Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 05-18-2010, 02:14 PM
arwar arwar is offline
Member
 
Join Date: May 2010
Posts: 31
Default delphi stringgrid colors

say i have a stringgrid 10 col by 10 row

how can i repaint 3 cells 3 different colors

say max number cell = clred
and min number cell=clblue
and mean cell = clyellow

where the max cell is [3,3] - the min is [6,4] and the mean is [7,9]

make [3,3] red; [6,4] blue; and [7,9] yellow

thanks
Reply With Quote
  #2  
Old 05-18-2010, 02:26 PM
arwar arwar is offline
Member
 
Join Date: May 2010
Posts: 31
Default add a bit more info

maybe i need to add some more info here.

the string grid gets constantly updated (every 3 minutes) with new data

so the max, mean and min cells are not always going to be the same cells.

so the program logic determines which are the max, etc, and i need to rewrite the celldraw event so i pass in 3 different cells to be painted 3 different colors
Reply With Quote
  #3  
Old 05-18-2010, 02:54 PM
arwar arwar is offline
Member
 
Join Date: May 2010
Posts: 31
Default I got it!!!!

procedure tform1.FillCell(Stringrid1 : TStringGrid; Col, Row : Integer;
BkCol, TextCol : TColor);
var
Rect : TRect;
begin
Rect := StringGrid1.CellRect(Col, Row);
with StringGrid1.Canvas do begin
Brush.Color := BkCol;
FillRect(Rect);
Font.Color := TextCol;
TextOut(Rect.Left + 2, Rect.Top + 2, Stringrid1.Cells[Col, Row]);
end;
end;

---/usage

procedure TForm1.Button1Click(Sender: TObject);
begin
FillCell(Stringgrid1,4,4,clYellow,clBlack);
FillCell(Stringgrid1,4,5,clRed,clBlack);

end;
Reply With Quote
  #4  
Old 05-18-2010, 03:00 PM
arwar arwar is offline
Member
 
Join Date: May 2010
Posts: 31
Default or even better

procedure tform1.FillCell(Stringrid1 : TStringGrid; Col, Row : Integer;
BkCol, TextCol : TColor);
var
Rect : TRect;
TempPString:Array [0..255] of char;
begin
Rect := StringGrid1.CellRect(Col, Row);
with StringGrid1.Canvas do begin
Brush.Color := BkCol;
FillRect(Rect);
StrPCopy(TempPString,StringGrid1.Cells[Col,Row]);
Font.Color := TextCol;
DrawText(StringGrid1.Canvas.Handle,TempPString,-1,Rect,DT_RIGHT);
// TextOut(Rect.Left + 2, Rect.Top + 2, Stringrid1.Cells[Col, Row]);
end;
end;

----the data is right justified = DT_RIGHT - super cool for numbers
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:24 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.