1

I use the following custom OnDraw to colorize background of a cell depending on column number:

procedure TForm_ControlPanel.aoc_gridDrawCell(Sender: TObject;
  ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
  grid: TStringGrid;
  S: string;
  SavedAlign: word;
begin
  grid := Sender as TStringGrid;
  if (ACol = 2) and (ARow >= 1) then
  begin
    S := grid.Cells[ACol, ARow]; // cell contents
    grid.Canvas.Brush.Color := clGreen;
    grid.Canvas.FillRect(Rect);
    SavedAlign := SetTextAlign(grid.Canvas.handle, TA_CENTER);
    grid.Canvas.TextRect(Rect, Rect.Left + (Rect.Right - Rect.Left) div 2,
      Rect.Top + 5, S);
    SetTextAlign(grid.Canvas.handle, SavedAlign);
    grid.Canvas.Brush := grid.Brush;
  end;
end;

but in the result i always have a "bar" on the left side which is not colored:

left part of cell not colored

I am using Delphi XE6.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Andreas Hinderberger
  • 1,505
  • 23
  • 41
  • Thanks Jerry. Haven't found that one. Adding a "Rect.Left := Rect.Left - 4;" inside the procedure solved it. – Andreas Hinderberger May 18 '14 at 04:37
  • 1
    I've rolled back your edit. If you want to include a solution to the problem yourself, do so in the form of an answer. Information on how to do so is provided in [Can I answer my own question?](http://stackoverflow.com/help/self-answer). – Ken White May 18 '14 at 05:17
  • And the rollback helps what? NOTHING!! Just that i have to come back another day to post the same as answer, which would cause more "confusions" since this post is already marked as "duplicate".... – Andreas Hinderberger May 18 '14 at 05:31
  • 1
    The rollback helps because a) it preserves the question as you posted it, and b) it teaches you (and others) the proper way to answer your own questions here (as does the link I provided you in my previous comment). – Ken White May 18 '14 at 05:47

0 Answers0