unit1.pas

来自「Delphi7应用编程150例附书源码.rar」· PAS 代码 · 共 50 行

PAS
50
字号
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  PolyArray:array of TPoint;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
    i:Integer;
    Count:Integer;
begin
    Count:=StrToInt(self.Edit1.Text);
    SetLength(PolyArray,Count+1);
    for i:=0 to Count-1 do
    begin
        PolyArray[i]:=Point(Trunc(Sin((2*PI)*i/Count)*100)+(self.Width div 2),
                            Trunc(Cos((2*PI)*i/Count)*100)+(self.Height div 3));
    end;
    PolyArray[Count]:=PolyArray[0];
    self.Refresh;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
    self.Canvas.Polyline(PolyArray);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?