Recent

Author Topic: TStringGrid: draw lines in OnPrepareCanvas?  (Read 967 times)

stem

  • Jr. Member
  • **
  • Posts: 88
TStringGrid: draw lines in OnPrepareCanvas?
« on: December 29, 2023, 10:37:56 pm »
Hi,

the lines

Code: Pascal  [Select][+][-]
  1. mygrid.Canvas.Pen.Color := clRed;
  2. mygrid.Canvas.Line(0, 0, 10, 10);

show no effect in the event "OnPrepareCanvas" of my TStringGrid whereas

Code: Pascal  [Select][+][-]
  1. mygrid.Canvas.Brush.Color := $004f4fe8;

works perfectly.

What am I doing wrong? Thank you.

stem

dsiders

  • Hero Member
  • *****
  • Posts: 1324
Re: TStringGrid: draw lines in OnPrepareCanvas?
« Reply #1 on: December 30, 2023, 02:58:24 am »
Hi,

the lines

Code: Pascal  [Select][+][-]
  1. mygrid.Canvas.Pen.Color := clRed;
  2. mygrid.Canvas.Line(0, 0, 10, 10);

show no effect in the event "OnPrepareCanvas" of my TStringGrid whereas

Code: Pascal  [Select][+][-]
  1. mygrid.Canvas.Brush.Color := $004f4fe8;

works perfectly.

What am I doing wrong? Thank you.

stem

OnPrepareCanvas is not meant for drawing operations... only configuring the canvas with the brush, pen, and font you need to use in DrawCell.

https://lazarus-ccr.sourceforge.io/docs/lcl/grids/tcustomgrid.onpreparecanvas.html
https://lazarus-ccr.sourceforge.io/docs/lcl/grids/tcustomgrid.ondrawcell.html
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

stem

  • Jr. Member
  • **
  • Posts: 88
Re: TStringGrid: draw lines in OnPrepareCanvas?
« Reply #2 on: January 04, 2024, 10:06:57 pm »
Thank you.

 

TinyPortal © 2005-2018