Recent

Author Topic: TCustomGrid.OnPaint is useless, misplaced line in sources.  (Read 653 times)

jamie

  • Hero Member
  • *****
  • Posts: 6995
TCustomGrid.OnPaint is useless, misplaced line in sources.
« on: June 14, 2025, 11:02:21 pm »
Trying to add an extra drawing ability to the drawgrid as to fill in the unused area with a custom bitmap brush.

  The idea is to allow the Grid to be sized passed the number of cells that exists there by leaving some space around it. I wanted to fill that area with a water mark type of brush indicating special features are available.

  There is an OnPaint event (not published) which is part of the customeControl class however, it gets called in the overridden PAINT handler inside the CustomGrid.Paint and thereby gets covered by all the following functions of updating the grid.
 Below is the final seciton of the Paint handler for the CustomGrid.Paint

Code: Pascal  [Select][+][-]
  1.   inherited Paint;  // <<<<< useless. gets overridden with following code.
  2.   if FUpdateCount=0 then begin
  3.     DrawEdges;
  4.     DrawAllRows;
  5.     DrawColRowMoving;
  6.     DrawBorder;
  7.   end;  
  8.   // Should be here.                    
  9.  

 I patched into the class locally to grab the Paint handler and then do my own custom painting outside the cell area.

 That worked fine but really, don't you think the OnPaint event should be corrected in its location of code? If so, one could even publish it.

Jamie

 
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6995
Re: TCustomGrid.OnPaint is useless, misplaced line in sources.
« Reply #1 on: June 15, 2025, 05:19:53 pm »
Something like this is what I was referring to. This isn't the actual background I am using but you get the idea.

The only true wisdom is knowing you know nothing

etrusco

  • New Member
  • *
  • Posts: 17
Re: TCustomGrid.OnPaint is useless, misplaced line in sources.
« Reply #2 on: July 03, 2025, 10:36:33 pm »
I agree, the event should be called last, and maybe only when FUpdateCount = 0.
I my opinion  OnPaint event is quite a hack, TDrawGrid should have some published Paint events for each of its area instead.
There are some things one could do with OnPrepareCanvas event, but indeed there's no event (besides OnPaint) one can hack to customize the "edges".

Will you file a ticket?

jamie

  • Hero Member
  • *****
  • Posts: 6995
Re: TCustomGrid.OnPaint is useless, misplaced line in sources.
« Reply #3 on: July 04, 2025, 12:08:31 am »
Does not seem like there are many interesting parties, which is fine with me. I got my code the way I wanted it.

For a more details of my paint event I used after I did a local class override and then implemented the OnPaint event.
Code: Pascal  [Select][+][-]
  1. procedure TTemplateForm.DrawPaint(Sender:TObject);
  2. const WaterText:String=' Limited Edition';
  3. Var
  4.   B:TBitMap;
  5.   R:Trect;
  6.   X,Y:Integer;
  7. Begin
  8.   B:= TBitMap.Create;
  9.   B.SetSize(B.Canvas.TextWidth(WaterText),20);
  10.   B.Canvas.Brush.Color := clGray;
  11.   B.Canvas.FillRect(B.Canvas.clipRect);
  12.   B.Canvas.Font.Color := clGray+$00101010;
  13.   B.canvas.TextOut(0,0,WaterText);
  14.   DrawGrid1.Canvas.Brush.Bitmap :=B;
  15.   R:=DrawGrid1.Cellrect(DrawGrid1.ColCount-1,DrawGrid1.RowCount-1);
  16.   R.Left := 0; R.Top:=0;
  17.   ExcludeCliprect(DrawGrid1.Canvas.handle,R.left,R.Top,R.Right,R.Bottom);
  18.   DrawGrid1.Canvas.FillRect(ClientRect);
  19.   SelectClipRgn(DrawGrid1.canvas.Handle, 0);
  20.   DrawGrid1.Canvas.Brush.BitMap:= Nil;
  21.   B.Free;
  22. end;
  23.  
  24.  

I was able to fill my uncovered areas with a nice water mark to explain to those that being cheap isn't always the best way!  :P
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018