Recent

Author Topic: [Solved] question about DrawCell  (Read 822 times)

Nono Reading Activity

  • Jr. Member
  • **
  • Posts: 56
[Solved] question about DrawCell
« on: March 09, 2024, 06:35:57 am »
Hello

I want to change the font color of TStringGrid's selected line : DrawCell event seems to be the even i have to use.
But at the same time, i use a procedure on FormCreate who check every Component and change Font, Color, Size, ....
When i add the DrawCell event, the modification added with the procedure are lost.
I can't find a way to make both work together.

thanks in advance.
« Last Edit: March 15, 2024, 06:20:08 am by Nono Reading Activity »

jamie

  • Hero Member
  • *****
  • Posts: 6801
Re: question about DrawCell
« Reply #1 on: March 09, 2024, 02:28:02 pm »
maybe the "OnPrepairCanvas" event will be what you need.
The only true wisdom is knowing you know nothing

Nono Reading Activity

  • Jr. Member
  • **
  • Posts: 56
Re: question about DrawCell
« Reply #2 on: March 09, 2024, 03:14:10 pm »
maybe the "OnPrepairCanvas" event will be what you need.
thanks, it helped a lot.
it change the current cell, now i need to find how to change the rest of the line
« Last Edit: March 09, 2024, 03:18:49 pm by Nono Reading Activity »

Nono Reading Activity

  • Jr. Member
  • **
  • Posts: 56
Re: question about DrawCell
« Reply #3 on: March 09, 2024, 03:51:16 pm »
with the following code, it work for the first line, but if i select another line, only the current cell will change to red and the previous will turn to black
the rest of the first line will still be red.
i'm probably not using canva the good way, but i don't know find of to correct it

Code: Pascal  [Select][+][-]
  1. procedure TMenu.TabPersonnagePrepareCanvas(Sender: TObject; aCol,
  2.   aRow: Integer; aState: TGridDrawState);
  3. var
  4.   LocColor: TColor;
  5.   IndC:     Integer;
  6. begin
  7.   if aRow > 0 then
  8.     begin
  9.       for IndC := 1 to TStringGrid(Sender).ColCount - 1 do
  10.         begin
  11.           if aRow = TStringGrid(Sender).Row then
  12.             LocColor := ClRed
  13.           else
  14.             LocColor := ClBlack;
  15.           TStringGrid(Sender).Canvas.Font.Color := LocColor;
  16.  
  17.           TStringGrid(Sender).Canvas.TextOut(TStringGrid(Sender).CellRect(IndC, aRow).Left + 2,
  18.                                               TStringGrid(Sender).CellRect(IndC, aRow).Top + 2,
  19.                                               TStringGrid(Sender).Cells[IndC, aRow]);
  20.         end;
  21.     end;
  22. end;  
  23.  

bytebites

  • Hero Member
  • *****
  • Posts: 698
Re: question about DrawCell
« Reply #4 on: March 09, 2024, 04:10:35 pm »
Try this
Code: Pascal  [Select][+][-]
  1. procedure TMenu.TabPersonnagePrepareCanvas(Sender: TObject; aCol,
  2.   aRow: Integer; aState: TGridDrawState);
  3. var
  4.   LocColor: TColor;
  5. begin
  6.   if aRow = TStringGrid(Sender).Row then
  7.             LocColor := ClRed
  8.           else
  9.             LocColor := ClBlack;
  10.   StringGrid(Sender).Canvas.Font.Color := LocColor;
  11. end;
  12.  
  13.  

Nono Reading Activity

  • Jr. Member
  • **
  • Posts: 56
Re: question about DrawCell
« Reply #5 on: March 09, 2024, 04:17:25 pm »
that was my first try, but it only change the current cell (and the other cells of the same aCol)




jamie

  • Hero Member
  • *****
  • Posts: 6801
Re: question about DrawCell
« Reply #6 on: March 09, 2024, 04:20:02 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
  2.   aState: TGridDrawState);
  3. begin
  4.   With TSTringGrid(Sender) Do begin
  5.    If ARow = Row Then
  6.    font.color := clGreen
  7.    Else
  8.    Font.Color := clBlue;
  9.   end;
  10. end;
  11.  
  12. procedure TForm1.StringGrid1Selection(Sender: TObject; aCol, aRow: Integer);
  13. begin
  14.   StringGrid1.Invalidate;
  15. end;                                          
  16.  
  17.  
The only true wisdom is knowing you know nothing

Nono Reading Activity

  • Jr. Member
  • **
  • Posts: 56
Re: question about DrawCell
« Reply #7 on: March 09, 2024, 04:26:26 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
  2.   aState: TGridDrawState);
  3. begin
  4.   With TSTringGrid(Sender) Do begin
  5.    If ARow = Row Then
  6.    font.color := clGreen
  7.    Else
  8.    Font.Color := clBlue;
  9.   end;
  10. end;
  11.  
  12. procedure TForm1.StringGrid1Selection(Sender: TObject; aCol, aRow: Integer);
  13. begin
  14.   StringGrid1.Invalidate;
  15. end;                                          
  16.  
  17.  
thanks a lot, it work :)

 

TinyPortal © 2005-2018