Search code examples
delphidelphi-xe2vcltstringgrid

How to change the color of TStringGrid grid-lines?


I've just finished migrating from D7 to XE2 and I've noticed that the default grid-lines are extremely faint (it doesn't help that I like to set the contrast on my monitor to high), as you can see in the screenshot below:

Default TStringGrid grid-lines

This was my attempt to re-color the lines darker by setting the TStringGrid's OnDrawCell event:

procedure TfrmBaseRamEditor.DrawStrGrid(Sender: TObject; ACol, ARow: Integer;
                                        Rect: TRect; State: TGridDrawState);
begin
    sgrSenden.Canvas.Pen.Color := clDkGray;
    // "Set the Style property to bsClear to eliminate flicker when the object
    // repaints" (I don't know if this helps).
    sgrSenden.Canvas.Brush.Style := bsClear;
    // Draw a line from the cell's top-right to its bottom-right:
    sgrSenden.Canvas.MoveTo(Rect.Right, Rect.Top);
    sgrSenden.Canvas.LineTo(Rect.Right, Rect.Bottom);
    // Make the horizontal line.
    sgrSenden.Canvas.LineTo(Rect.Left, Rect.Bottom);
    // The other vertical line.
    sgrSenden.Canvas.LineTo(Rect.Left, Rect.Top);
end;

But this produces a result even less desirable, notice especially the border of the active cell:

attempt to modify gridlines

Is there any way to make these grid-lines darker or thicker in a way that doesn't look as ugly as my attempt?


Solution

  • As per the answer to this question, I simply set DrawingStyle property of the TStringGrid to gdsClassic.