Delphi动态创建的paintbox3绘制曲线时却显示不出曲线,怎么回事啊?急

cumtxjb 2008-09-04 10:03:02
如题,代码如下:
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.
...全文
140 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zwjchina 2008-09-05
  • 打赏
  • 举报
回复
//*****************在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;
这代码需要放入到PaintBox的OnPaint事件中处理。

先实现一个函数:
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
PaintBox: TPaintBox;
begin
PaintBox := Sender as TPaintBox;
PaintBox.Canvas.lineto(50,50);
PaintBox.canvas.Font.Color:=clBlue;
PaintBox.canvas.Font.Size:=30;
PaintBox.canvas.Pen.Width:=100;
PaintBox.canvas.TextOut(5,5,'test');
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;
OnPaint := PaintBox1Paint; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
end;
PaintBox3.Parent:=FdrawGraphic;
cumtxjb 2008-09-05
  • 打赏
  • 举报
回复
在线等待,还望好心人救俺一命!
zwjchina 2008-09-05
  • 打赏
  • 举报
回复
这句实际相当于强制类型转换。
cumtxjb 2008-09-05
  • 打赏
  • 举报
回复
2楼厉害!大恩不言谢!给分,结贴去!还想再请教一下:

先实现一个函数:
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
PaintBox: TPaintBox;
begin
[color=#FF0000]PaintBox := Sender as TPaintBox; //这里是什么意思呢?[/color]
PaintBox.Canvas.lineto(50,50);
PaintBox.canvas.Font.Color:=clBlue;
PaintBox.canvas.Font.Size:=30;
PaintBox.canvas.Pen.Width:=100;
PaintBox.canvas.TextOut(5,5,'test');
end;

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧