问题
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.
回答1:
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
.
回答2:
You can use the StringGrid1.CellRect(ACol, ARow)
that returns the actual TRect of the cell instead of using the parameter Rect
.
回答3:
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.
回答4:
Since you're drawing the grid cell yourself then just turn off the grid property DefaultDrawing, set it to false.
来源:https://stackoverflow.com/questions/8806212/fillrect-doesnt-paint-the-complete-tstringgrid-cell-in-delphi-xe2