unit Unit1;
{先設置畫筆畫刷}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
btn: TButton;
const
y1 = 10;
y2 = 80;procedure TForm1.FormCreate(Sender: TObject);
{繪制橢圓; 橢圓的參數和矩形是一樣的}
begin
Canvas.Pen.Width := 2;
Canvas.Pen.Color := clRed;
Canvas.Brush.Color := clWhite;
end;procedure TForm1.Button1Click(Sender: TObject);
{根據矩形結構繪制橢圓}
begin
btn := TButton(Sender);
Canvas.Ellipse(btn.Left, y1, btn.Left+btn.Width, y2);
end;procedure TForm1.Button2Click(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.Button3Click(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.Button4Click(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.Button5Click(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;
end.