Solved

Font for a cell in StringGrid

Posted on 2001-06-06
1
496 Views
Last Modified: 2013-12-03
How can have the text in a specific cell in a different color ?
Thanks
0
Comment
Question by:syloux
[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
1 Comment
 
LVL 8

Accepted Solution

by:
Cesario earned 50 total points
ID: 6159691
Hi syloux,

Use the "OnDrawCell"-event to make your StringGrids colorful! The following Code shows how to give your Grid a red background color. The second column will be colored with green background.


procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);

Const   //define your color here. Of course you
        //can use default colors too.
  clPaleGreen = TColor($CCFFCC);
  clPaleRed =   TColor($CCCCFF);

begin

//Does the cell have the focus you have to paint it with other colors
if (gdFocused in State) then begin    
   StringGrid1.Canvas.Brush.Color := clBlack;
   StringGrid1.Canvas.Font.Color := clWhite;
end
else  //Does the cell have NOT the focus you can use
       //your personal colors here

   if ACol = 2   //the second Column should be
                 //green, the other cells red
    then StringGrid1.Canvas.Brush.color := clPaleGreen
    else StringGrid1.canvas.brush.Color := clPaleRed;

//Now Paint the cells, but only, if the cell isn't the Title- Row/Column
//This of course depends whether you have title-Row/Columns or not.

If (ACol > 0) and (ARow>0) then
  begin
      //Painting the Background
    StringGrid1.canvas.fillRect(Rect);

      //Painting the Text. Here you can improve the code with
      // using alignment and so on.
    StringGrid1.canvas.TextOut(Rect.Left,Rect.Top,StringGrid1.Cells[ACol,ARow]);
  end;
end;
0

Featured Post

Technology Partners: 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
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…
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

615 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