?
Solved

Color of text in cells of a TStringGrid

Posted on 2015-02-12
3
Medium Priority
?
132 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 1000 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

770 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