unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TMyDrawingControl }
TMyDrawingControl = class(TCustomControl)
private
FRedGrid: boolean;
procedure SetRedGrid(AValue: boolean);
public
procedure Paint; override;
property RedGrid: boolean read FRedGrid write SetRedGrid;
end;
{ TForm1 }
TForm1 = class(TForm)
CheckBox1: TCheckBox;
MyDrawingControl: TMyDrawingControl;
procedure CheckBox1Change(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TMyDrawingControl.SetRedGrid(AValue: boolean);
begin
if FRedGrid=AValue then Exit;
FRedGrid:=AValue;
Paint;
end;
procedure TMyDrawingControl.Paint;
var
x, y: Integer;
begin
// Draws the background
Canvas.Pen.Color := clWhite;
Canvas.Rectangle(0, 0, Width, Height);
// Draws squares
if RedGrid then
Canvas.Pen.Color := clRed
else
Canvas.Pen.Color := clBlack;
for x := 1 to 8 do
for y := 1 to 8 do
Canvas.Rectangle(Round((x - 1) * Width / 8), Round((y - 1) * Height / 8),
Round(x * Width / 8), Round(y * Height / 8));
inherited Paint;
end;
{ TForm1 }
procedure TForm1.CheckBox1Change(Sender: TObject);
begin
MyDrawingControl.RedGrid:= CheckBox1.Checked;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyDrawingControl := TMyDrawingControl.Create(Self);
MyDrawingControl.Align := alClient;
MyDrawingControl.Parent := Self;
MyDrawingControl.DoubleBuffered := True;
MyDrawingControl.RedGrid:= True;
CheckBox1.Checked:= True;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
end;
end.