Recent

Author Topic: [Solved] TsWorksheetGrid: How to have two colors in the same cell  (Read 1775 times)

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 630
    • Double Dummy Solver - free download
The goal is to have the diamond or heart suit symbol shown in red, with the rest of the cell's text in black. Never more than one symbol in a cell.
As a starter, I'm just trying to paint those entire cells myself in red, but even that eludes me. Another issue, how do I prevent Laz from repainting those cells?
I've set up on OnDrawCell event like this:
Code: Pascal  [Select][+][-]
  1.     s := Grid.Worksheet.ReadAsText(aRow, aCol);
  2.     i := pos('♦', s);
  3.     if i = 0 then
  4.       i := pos('♥', s);
  5.     if i <> 0 then
  6.     begin
  7.       Grid.Canvas.font.Color := clRed;
  8.       Grid.Canvas.TextOut(1,1, s);
  9.     end; // make red  

« Last Edit: August 07, 2018, 08:28:38 pm by bobonwhidbey »
Lazarus 3.8 FPC 3.2.2 x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 13363
Re: TsWorksheetGrid: How to have two colors in the same cell
« Reply #1 on: August 07, 2018, 07:12:29 pm »
Use html codes in the cell text:
Code: Pascal  [Select][+][-]
  1.   sWorksheetGrid1.Cells[1, 1] := 'Red <font color="red">♥</font> - green <font color="green">♦</font>';
  2.   sWorksheetGrid1.Worksheet.WriteTextAsHTML(2, 0, 'Red <font color="red">&hearts;</font> - green <font color="green">&diams;</font>');

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 630
    • Double Dummy Solver - free download
Re: TsWorksheetGrid: How to have two colors in the same cell
« Reply #2 on: August 07, 2018, 08:28:23 pm »
Thank you wp....now I won't even have to use an OnDrawCell event
Lazarus 3.8 FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018