FillRect doesn't paint the complete TStringGrid cell in Delphi XE2

5.7k views Asked by At

FillRect doesn't paint the complete TStringGrid cell in Delphi XE2. There is a gap of 3 pixels on the left side in the default color (with BiDiMode set to bdLeftToRight). This problem doesn't exist in Delphi 6 which I used before.

procedure TShapeline.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  Stringgrid1.Canvas.Brush.Color:=$00FF80FF;
  StringGrid1.Canvas.FillRect(Rect);
end;

I tried to change all properties (including the DrawingStyle) and different brush styles, the painted rectangle doesn't fill the complete cell.

4

There are 4 answers

1
LeoEuclides On

You can use the StringGrid1.CellRect(ACol, ARow) that returns the actual TRect of the cell instead of using the parameter Rect.

5
Bruce McGee On

Turn off the first 4 options in TStringGrid:

  • goFixedVertLine
  • goFixedHorizLine
  • goVertLine
  • goHorizLine

Then it won't paint the grid lines, and your grid cells will paint right to the edges. Just tried it with XE.

5
Uwe Raabe On

This is expected behaviour in XE2 when DefaultDrawing = true and themes are enabled (I'm not going to argue about good or bad here - as you might have noticed, the behaviour is different for RigthToLeft mode...).

A workaround is to check for this condition and decrement Rect.Left by 4 pixel before calling FillRect.

1
Mike On

Since you're drawing the grid cell yourself then just turn off the grid property DefaultDrawing, set it to false.