Recent

Author Topic: How to set font size in TTextStyle for a StringGrid?  (Read 2174 times)

Jvan

  • Full Member
  • ***
  • Posts: 181
How to set font size in TTextStyle for a StringGrid?
« on: August 25, 2020, 11:14:08 pm »
My Stringgrid by default has a font size in 12, but because of using this that columns have a inferior font size.

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.myGridPrepareCanvas(sender: TObject; aCol,
  2.   aRow: Integer; aState: TGridDrawState);
  3. var
  4.   MyTextStyle: TTextStyle;
  5. begin
  6.   if (aRow >= myGrid.FixedRows) then begin
  7.     if (aCol = 1) then begin
  8.       MyTextStyle.Alignment := taCenter;
  9.       myGrid.Canvas.TextStyle := MyTextStyle;
  10.  
  11.     end else if (aCol = 4) then begin
  12.       MyTextStyle.Alignment := taRightJustify;
  13.       myGrid.Canvas.TextStyle := MyTextStyle;
  14.     end;
  15.   end;
  16.  
  17. end;
  18.  

wp

  • Hero Member
  • *****
  • Posts: 13329
Re: How to set font size in TTextStyle for a StringGrid?
« Reply #1 on: August 26, 2020, 12:19:33 am »
TTextStyle is a record. You must initialize the local variable MyTextStyle correctly - the way you do it all fields except for Alignment contain random data

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.myGridPrepareCanvas(sender: TObject; aCol,
  2.   aRow: Integer; aState: TGridDrawState);
  3. var
  4.   MyTextStyle: TTextStyle;
  5. begin
  6.   if (aRow >= myGrid.FixedRows) then begin
  7.     MyTextStyle := myGrid.Canvas.TextStyle;  // <--- initialize MyTextStyle with the current TextStyle of the grid's canvas.
  8.     if (aCol = 1) then begin
  9.       MyTextStyle.Alignment := taCenter;
  10.       myGrid.Canvas.TextStyle := MyTextStyle;
  11.  
  12.     end else if (aCol = 4) then begin
  13.       MyTextStyle.Alignment := taRightJustify;
  14.       myGrid.Canvas.TextStyle := MyTextStyle;
  15.     end;
  16.   end;
  17.  
  18. end;

Jvan

  • Full Member
  • ***
  • Posts: 181
Re: How to set font size in TTextStyle for a StringGrid?
« Reply #2 on: August 26, 2020, 12:33:48 am »
Thanks!

 

TinyPortal © 2005-2018