刚好手边有一个例子,给你贴出来看看。用canvas画的,变量 x 是基于窗体的。
---------------------
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer; x,y:real; halfheight:integer;
begin
form1.Refresh;
halfheight:=form1.Height div 2;
for i:=1 to trunc(form1.Width) do
begin
x:=i*(4*PI/form1.Width);
y:=sin(x); //halfheight*0.7
j:=trunc(y*100)+halfheight;
canvas.Pixels[i,j]:=clred;
end;
x:=3*form1.Width/4; //画竖线
i:=trunc(x);
with canvas do
begin
pen.Color:=clgreen;
moveto(i,0);
lineto(i,form1.Height);
end;
end;
procedure TForm1.FormPaint(Sender: TObject);
var x,y:real; i,j:integer;
begin
x:=form1.Width/4; //坐标系
i:=trunc(x);
y:=form1.Height/2;
j:=trunc
;
with canvas do
begin
moveto(i,0);
lineto(i,form1.Height);
moveto(0,j);
lineto(form1.Width,j);
end;
end;