[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Color of text in cells of a TStringGrid

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 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