Solved

Color of text in cells of a TStringGrid

Posted on 2015-02-12
3
123 Views
Last Modified: 2015-02-12
Depending on some condition, I want to have text in specific TStringGrid cells be (for example) written in RED.
So I have to code in the DrawCell event
But I am not sure of which property of which object I have to set to clRed
To write the text, I code this :
Canvas.TextOut(Rect.Left, Rect.Top,SG.Cells[ACol,ARow]);
But what shall I set to clRed ?
0
Comment
Question by:LeTay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 250 total points
ID: 40605334
StringGrid.canvas.Brush.Color := clRed;
0
 
LVL 24

Expert Comment

by:jimyX
ID: 40605347
Brush sets the cell. But, if you want to set only the font:
StringGrid.canvas.Font.Color:= clRed;
0
 
LVL 27

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 250 total points
ID: 40605352
This is example how to use OnCellDraw event in stringgrid:
procedure TForm1.MyStrGridDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var
  s : string;
begin
  inherited;

  try
    if (ACol > 0) and (ARow > 0) then
    begin
      s := MyStrGrid.Cells[ACol, ARow];

      if gdSelected in State then
      begin
        MyStrGrid.Canvas.Brush.Color := clHighlight;
        MyStrGrid.Canvas.Font.Color := clHighlightText;
        MyStrGrid.Canvas.Font.Style := [fsBold];
      end
      else
      begin
        if s = 'some text' then
          MyStrGrid.Canvas.Font.Color := clRed
        else
          MyStrGrid.Canvas.Font.Color := clWindowText;

        MyStrGrid.Canvas.Font.Style := [];
      end;

      MyStrGrid.Canvas.Brush.Style := bsSolid;
      MyStrGrid.Canvas.FillRect(Rect);
      MyStrGrid.Canvas.TextOut(Rect.Left, Rect.Top, s);
    end;
  except
  end;
end;

Open in new window


... this example check if 'some text' is in cell and draw it in red.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question