procedure TForm1.Panel1Paint(Sender: TObject);
const
COLOR1 = TColor($F0F0F0);
COLOR2 = TColor($E0E0E0);
var
dx: Integer;
x: Integer;
i: Integer;
begin
dx := round(ScreenInfo.PixelsPerInchX / 25.4);
with Panel1 do begin
Canvas.Brush.Color := clWhite;
Canvas.FillRect(0, 0, Width, Height);
Canvas.Pen.Width := 1;
Canvas.Pen.Style := psSolid;
// vertical grid lines
x := 0;
for i := 0 to MaxInt do
begin
if i mod 10 = 0 then
Canvas.Pen.Color := COLOR2
else
Canvas.Pen.Color := COLOR1;
Canvas.Line(x, 0, x, Height);
inc(x, dx);
if x > Width then break;
end;
// horizontal grid lines
// ...
end;
end;