本例效果圖:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
R: TRect;
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption := '繪制矩形';
Button2.Caption := '反色';
Self.Color := clWhite;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
R := Bounds(20, 20, 150, 100);
Randomize;
Canvas.Brush.Color := Random($FFFFFF);
Canvas.Pen.Color := Random($FFFFFF);
Canvas.Pen.Width := 10;
Canvas.Rectangle(R);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
InvertRect(Canvas.Handle, R);
end;
end.