procedure TForm1.btn1Click(Sender: TObject);
begin
Canvas.Pen.Color := clRed;
Canvas.Pen.Width := 2;
Canvas.MoveTo(0, 0);
Canvas.LineTo(ClientWidth, ClientHeight);
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
Canvas.Brush.Color := clYellow;
Canvas.FillRect(ClientRect);
end;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
btn2: TButton;
btn3: TButton;
btn4: TButton;
btn5: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btn3Click(Sender: TObject);
procedure btn5Click(Sender: TObject);
procedure btn4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
btn: TButton;
const
y1 = 10;
y2 = 80;
procedure TForm1.btn1Click(Sender: TObject);
begin
btn := TButton(Sender);
Canvas.Rectangle(btn.Left, y1, btn.Left+btn.Width, y2);
end;
procedure TForm1.btn2Click(Sender: TObject);
var
r: TRect;
begin
btn := TButton(Sender);
r := Rect(btn.Left, y1, btn.Left+btn.Width, y2);
Canvas.Rectangle(r);
end;
procedure TForm1.btn3Click(Sender: TObject);
begin
btn := TButton(Sender);
Canvas.RoundRect(btn.Left, y1, btn.Left+btn.Width, y2, 20, 20);
end;
procedure TForm1.btn4Click(Sender: TObject);
var
r: TRect;
begin
btn := TButton(Sender);
r := Rect(btn.Left, y1, btn.Left+btn.Width, y2);
Canvas.FrameRect(r);
end;
procedure TForm1.btn5Click(Sender: TObject);
var
r: TRect;
begin
btn := TButton(Sender);
r := Rect(btn.Left, y1, btn.Left+btn.Width, y2);
Canvas.DrawFocusRect(r);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Canvas.Pen.Color := clGreen;
Canvas.Pen.Width := 2;
Canvas.Brush.Color := clWhite;
end;
end.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
btn2: TButton;
btn3: TButton;
btn4: TButton;
btn5: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btn3Click(Sender: TObject);
procedure btn5Click(Sender: TObject);
procedure btn4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
btn: TButton;
const
y1 = 10;
y2 = 80;
procedure TForm1.btn1Click(Sender: TObject);
begin
btn := TButton(Sender);
Canvas.Ellipse(btn.Left, y1, btn.Left+btn.Width, y2);
end;
procedure TForm1.btn2Click(Sender: TObject);
var
r: TRect;
begin
btn := TButton(Sender);
r := Rect(btn.Left, y1, btn.Left+btn.Width, y2);
Canvas.Ellipse(r);
end;
procedure TForm1.btn3Click(Sender: TObject);
begin
btn := TButton(Sender);
Canvas.Pie(
btn.Left, y1, btn.Left+btn.Width, y2,
btn.Left+btn.Width, y1+((y2-y1) div 2),
btn.Left+btn.Width div 2, y1);
end;
procedure TForm1.btn4Click(Sender: TObject);
begin
btn := TButton(Sender);
Canvas.Chord(
btn.Left, y1, btn.Left+btn.Width, y2,
btn.Left+btn.Width, y1+((y2-y1) div 2),
btn.Left+btn.Width div 2, y1);
end;
procedure TForm1.btn5Click(Sender: TObject);
begin
btn := TButton(Sender);
Canvas.Arc(
btn.Left, y1, btn.Left+btn.Width, y2,
btn.Left+btn.Width, y1+((y2-y1) div 2),
btn.Left+btn.Width div 2, y1);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Canvas.Pen.Color := clGreen;
Canvas.Pen.Width := 2;
Canvas.Brush.Color := clWhite;
end;
end.
![](https://pic002.cnblogs.com/images/2011/166472/2011052112540041.png)