Solved

Color of text in cells of a TStringGrid

Posted on 2015-02-12
3
112 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
  • 2
3 Comments
 
LVL 24

Accepted Solution

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

Expert Comment

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

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 250 total points
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now