procedure TForm1.DrawGrid(ACanvas: TCanvas; AScaleFactor: Integer);
var
lPoint: TPoint;
lCount, lScale, i: Integer;
begin
ACanvas.Brush.Style:= bsSolid;
ACanvas.Brush.Color:= clWhite;
ACanvas.FillRect(ACanvas.ClipRect);
//X-Achse
ACanvas.TextOut(0,0, RectToStr(ACanvas.ClipRect));
ACanvas.MoveTo(0, GetHeight(ACanvas.ClipRect)
div 2);
//Graph
ACanvas.LineTo(GetWidth(ACanvas.ClipRect), GetHeight(ACanvas.ClipRect)
div 2);
//Mittelpunkt ausrechnen
lPoint:= GetCenter(ACanvas.ClipRect);
//Scalierungswert festlegen
//Mittelpunkt bis Rechts - X-Achse
i:= lPoint.X;
lCount:= 0;
lScale:= AScaleFactor;
while i < ACanvas.ClipRect.Right
do
begin
inc(i,lScale);
inc(lCount,1);
DrawGridCaption(ACanvas, Point(i, lPoint.Y), 0, IntToStr(lCount));
end;
//Mittelpunkt bis Links der X-Achse
i:= lPoint.X;
lScale:= AScaleFactor;
lCount:= 0;
while i > ACanvas.ClipRect.Left
do
begin
dec(i, lScale);
dec(lCount, 1);
DrawGridCaption(ACanvas, Point(i, lPoint.Y), 2, IntToStr(lCount));
end;
//Y-Achse Von Mittelpunkt nach unten
lPoint:= GetCenter(ACanvas.Cliprect);
lScale:= AScaleFactor;
i:=lPoint.Y;
lCount:= 0;
while i < ACanvas.ClipRect.Bottom
do
begin
inc(i, lScale);
inc(lCount, -1);
DrawGridCaption(ACanvas, Point(lPoint.X, i), 1, IntToStr(lCount));
end;
//Y-Achse von Mittelpunkt nach oben
lPoint:= GetCenter(ACanvas.Cliprect);
lScale:= AScaleFactor;
i:=lPoint.Y;
lCount:= 0;
while i > ACanvas.ClipRect.Top
do
begin
dec(i, lScale);
dec(lCount, -1);
DrawGridCaption(ACanvas, Point(lPoint.X, i), 3, IntToStr(lCount));
end;
//Y-Achse
ACanvas.MoveTo(GetWidth(ACanvas.ClipRect)
div 2, 0);
//Graph
ACanvas.LineTo(GetWidth(ACanvas.ClipRect)
div 2, GetHeight(ACanvas.ClipRect));
end;
.....
function GetScaleValue(APos: Integer): Integer;
begin
Result:= ((APos + 10) + 1) * 10;
end;