Delphi动态创建的paintbox3绘制曲线时却显示不出曲线,怎么回事啊?急
如题,代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, sgr_def, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
sp_XYPlot1: Tsp_XYPlot;
Shape1: TShape;
PaintBox1: TPaintBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Tform1.Button1Click(Sender: TObject);
Var
Plot3:Tsp_XYPlot; //请注意:Plot3和Shape3的parent属性均是
FDrawGraphic:TForm; //FDrawGraphic
shape3:Tshape;//三组数据曲线所用
paintbox3:Tpaintbox;
begin
//Form1.Refresh;
FDrawGraphic:=TForm.Create(self);
with FdrawGraphic do
begin
caption:='曲线';
width:=800;
Height:=600;
left:=trunc(screen.Width/2-width/2);
top:=trunc(screen.Height/2-height/2);
end;
FDrawGraphic.Show;
//*******************shape3的创建**********************//
shape3:=Tshape.Create(self);
shape3.Parent:=FDrawGraphic;
with shape3 do
begin
width:=FdrawGraphic.Width-100; //只要FdrawGraphic的Height,Width确定了,Shape3
Height:=FdrawGraphic.Height-100; //和Tsp_XYPlot的位置及尺寸也就确定了,其中shape3的
left:=50; //尺寸比FDrawGraphic小20,Tsp_XYPlot比FDrawGraphic小30
Top:=50; //位置均位于窗体的中央
end;
//****************************************************//
//*********************panitBox3的创建*****************//
paintBox3:=TpaintBox.Create(self);
with paintBox3 do //使paintBox3的尺寸和位置和shape3的完全一致
begin
width:=100(*shape3.Width*);
Height:=100(*shape3.Height*);
left:=shape3.Left;
top:=shape3.Top;
end;
PaintBox3.Parent:=FdrawGraphic;
//*****************************************************//
(* Plot3:=Tsp_XYPlot.Create(self);
with Plot3 do
begin
width:=FdrawGraphic.Width-200; //只要FdrawGraphic的Height,Width确定了,Shape3
Height:=FdrawGraphic.Height-200; //和Tsp_XYPlot的位置及尺寸也就确定了,其中shape3的
left:=100; //尺寸比FDrawGraphic小20,Tsp_XYPlot比FDrawGraphic小30
Top:=100;
with BottomAxis do
begin
SetMinMax(0,500);
ticksCount:=6;
end;
with leftAxis do
begin
SetMinMax(0,1500);
ticksCount:=6;
end;
with rightAxis do
begin
SetMinMax(0,3500);
ticksCount:=6;
NoTicks:=False;
GridAttr.Visible:=true;
NoTicksLabel:=False;
end;
Parent:=FdrawGraphic;
end; *)
//*****************在paintBox3中输出文字******************// 主要是这里,请同志们看看!
with paintBox3 do
begin
with canvas do
lineto(50,50);
canvas.Font.Color:=clBlue;
canvas.Font.Size:=30;
canvas.Pen.Width:=100;
canvas.TextOut(5,5,'test');
//canvas.textout(trunc(shape3.Width/2),trunc((shape3.Height-Plot3.Height)/4),'***曲线');
end;
//****************************************************//
end;
procedure TForm1.Button2Click(Sender: TObject);//
begin
//**********************调试用************************//
paintBox1.Canvas.TextOut(2,2,'Test');
with paintbox1.Canvas do
begin
moveto(0,0);
LineTo(50,50);
end;
//***************************************************//
end;
end.