unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
procedure FormCreate(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
R: TRect;
bSel: Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
PaintBox1.Width := 120; PaintBox1.Height := 120;
R.Top := 10; R.Left := 10; R.Right := 110; R.Bottom := 110;
bSel := False;
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
const
radii: Byte = 3;
begin
with PaintBox1.Canvas do
begin
Brush.Color := clWhite;
Ellipse(R);
if bSel then
begin
Brush.Color := clBlack;
Rectangle(R.Top - radii, (R.Left+R.Right) div 2 - radii, R.Top + radii, (R.Left+R.Right) div 2 + radii);
Rectangle(R.Bottom - radii, (R.Left+R.Right) div 2 - radii, R.Bottom + radii, (R.Left+R.Right) div 2 + radii);
Rectangle((R.Left+R.Right) div 2 - radii, R.Top - radii, (R.Left+R.Right) div 2 + radii, R.Top + radii);
Rectangle((R.Left+R.Right) div 2 - radii, R.Bottom - radii, (R.Left+R.Right) div 2 + radii, R.Bottom + radii);
end;
end;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if bSel then
begin
bSel := False;
Invalidate;
end;
end;
procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if PtInRegion(CreateEllipticRgnIndirect(R), X, Y) then
begin
if not bSel then
begin
bSel := True;
Invalidate;
end;
end
else if bSel then
begin
bSel := False;
Invalidate;
end
end;
end.