Recent

Author Topic: [SOLVED]How to avoid drawing the focused rect on a stringgrid cell?  (Read 4281 times)

kinlion

  • Jr. Member
  • **
  • Posts: 82
  • I Love Lazarus
In TStringGrid's OnDrawCell event, I can draw anything except erase the focused rect, because it is drawn after that event.
I tried to set Canvas.Pen.Style to psClear in OnPrepareCanvas event, but no use.
My StringGrid Options includes goRowSelect.
 :(
« Last Edit: December 08, 2018, 07:51:21 am by kinlion »

wp

  • Hero Member
  • *****
  • Posts: 11922
Re: How to avoid drawing the focused rect on a stringgrid cell?
« Reply #1 on: November 27, 2018, 10:28:38 am »
You cannot do it with the standard events. But you can derive a new TStringGrid from the current class and override the DrawFocusRect method to paint nothing. Since this does not affect any properties you can even keep the class name:

Code: Pascal  [Select][+][-]
  1. type
  2.   TStringGrid = type(Grids.TStringGrid)  
  3.   protected
  4.     procedure DrawFocusRect(aCol,aRow: Integer; ARect: TRect); override;
  5.   end;
  6. ...
  7. procedure TStringGrid.DrawFocusRect(aCol, aRow: Integer; ARect: TRect);
  8. begin
  9.   // Do nothing
  10. end;

If you only have one string grid in your project you can add this code to the unit in which it is used. Or, if you have several grids, put it into its own unit and add this unit to the *end* of the uses clauses of all units with strings grids. Having the new unit at the end of the uses clause (or to be more precise: after the grids unit) makes it replace the standard TStringGrid.

[EDIT]
howardpc in the following post is right: it should be "class(Grids.TStringGrid)" instead of "type(Grids.TStringGrid)".
« Last Edit: November 27, 2018, 10:47:23 am by wp »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to avoid drawing the focused rect on a stringgrid cell?
« Reply #2 on: November 27, 2018, 10:38:18 am »
Slip of the pen.
I'm sure wp meant
Code: Pascal  [Select][+][-]
  1. type   TStringGrid = class(Grids.TStringGrid)
  2.   ...

kinlion

  • Jr. Member
  • **
  • Posts: 82
  • I Love Lazarus
Re: How to avoid drawing the focused rect on a stringgrid cell?
« Reply #3 on: November 27, 2018, 10:43:38 am »
Thanks to all.

I haved derived a new class as wp said :)

 

TinyPortal © 2005-2018