procedure DrawDotGrid(aCanvas:TCanvas; aWidth, aHeight, aPosX, aPosY, aDotX, aDotY, aDotSize, aDotColor, aBackColor: integer); var DotBrush : TBitmap; BackBuf : TBitmap; begin BackBuf := TBitmap.Create; try BackBuf.Width := aWidth; BackBuf.Height:= aHeight; BackBuf.PixelFormat := pf32bit; DotBrush := TBitmap.Create; try DotBrush.Width := aDotX+1; DotBrush.Height:= aDotY+1; DotBrush.PixelFormat := pf32bit; DotBrush.Canvas.Brush.Color := aBackColor; DotBrush.Canvas.FillRect(DotBrush.Canvas.ClipRect); if aDotSize = 1 then DotBrush.Canvas.Pixels[aDotX, aDotY] := aDotColor else begin DotBrush.Canvas.Brush.Color := aDotColor; DotBrush.Canvas.Pen.Color := aBackColor; DotBrush.Canvas.Rectangle(aDotX-aDotSize-1, aDotY-aDotSize-1, aDotX+1, aDotY+1); end; BackBuf.Canvas.Brush.Bitmap := DotBrush; BackBuf.Canvas.FillRect(BackBuf.Canvas.ClipRect); aCanvas.Draw(aPosX, aPosY, BackBuf); finally DotBrush.Free; end; finally BackBuf.Free; end; end;
procedure TForm32.PaintBox1Paint(Sender: TObject); begin DrawDotGrid(PaintBox1.Canvas, PaintBox1.Width-10, PaintBox1.Height-10, 5, 5, PaintBox1.Width div 10, PaintBox1.Height div 10, 2, clRed, clWhite); end;