Re: StringGrid: How to change the font colour of a cell
"Rory Daulton" <[email protected]>
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <001b01c34c52$ccd869b0$6401a8c0@laptop> |
smching2001, > I want to change the cell font colour of the StringGrid when it meet > certain criteria. > > For example, when user enter a value of 100 in the cell, its font > then change to red colour. Below is some code from Lloyd's Help File. This changes both the font color and the background color of the cell. Rory Daulton [email protected] Campus Crusade for Christ Q: How do I highlight selected fields on a TStringGrid? A: procedure TForm1.Button1Click(Sender: TObject); var i: integer; begin stringGrid1.DefaultDrawing := false; with StringGrid1 do begin colCount := 26; RowCount := 99; for i := 1 to 20 do cells[i, 0] := chr(i + 64); for i := 0 to 99 do cells[0, i + 1] := IntToStr(i); end; end; procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Longint; Rect: TRect; State: TGridDrawState); begin if (stringGrid1.cells[col, row][1] = '1') and (Col = 0) then begin stringGrid1.canvas.brush.color := clMaroon; stringGrid1.canvas.font.color := clWhite; end else begin stringGrid1.canvas.brush.color := clWhite; stringGrid1.canvas.font.color := clMaroon; end; stringGrid1.canvas.fillRect(rect); stringGrid1.canvas.TextRect(Rect, Rect.Left + 3, Rect.Top + 3, StringGrid1.cells[col, row]); end; { This code came from Lloyd's help file! } --- [This E-mail scanned for viruses by Declude Virus and Nmax "Your MAXimum Connection!"] [This E-mail scanned for spam by Declude JunkMail and Nmax "Your MAXimum Connection!"] ------------------------ Yahoo! Groups Sponsor ---------------------~--> Buy Naturally Painless & Spray Away Backaches & Joint Pain. $19.97 http://www.challengerone.com/t/l.asp?cid=2867&lp=m331.html http://us.click.yahoo.com/tJIe0D/79VGAA/ySSFAA/i7folB/TM ---------------------------------------------------------------------~-> CodeCoffer - new Delphi code protection Tool! http://www.delphicollection.com/public/CodeCoffer.htm --------------------------------------------------------------- Unsubscribe:[email protected] List owner:[email protected] --------------------------------------------------------------- Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/