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.
...全文
224 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;
内容概要:本文针对无刷直流电机驱动的电子机械制动(EMB)执行器,建立了考虑Stribeck摩擦特性的非线性耦合动力学模型,并在Simulink环境中完成了系统级仿真分析。研究综合集成了电机动力学、齿轮传动机构与制动执行机构的动力学特性,构建了高保真的机电一体化系统模型。重点引入Stribeck摩擦模型以精确描述低速工况下执行器内部存在的静摩擦、粘滞摩擦与库仑摩擦之间的过渡行为,有效提升了系统在启停、反向运动等瞬态过程中的动态响应仿真精度。通过多工况仿真验证了模型的有效性,能够准确反映摩擦引起的爬行、滞后与定位误差等非线性现象,为EMB系统的高性能控制算法设计(如摩擦补偿、滑模控制)与结构优化提供了高可信度的仿真平台。; 适合人群:从事汽车电子制动系统、电机驱动控制、机电系统建模与仿真研究的研究生、科研人员及工程技术人员,需具备扎实的机械动力学、自动控制理论基础和MATLAB/Simulink仿真能力。; 使用场景及目标:①用于高精度电子机械制动系统的设计验证与性能预测;②为消除摩擦非线性影响的先进控制策略(如自适应控制、智能控制)提供精确的被控对象模型;③深入探究Stribeck摩擦等非线性因素对系统动态性能(如响应延迟、稳态误差)的作用机理; 阅读建议:读者应结合提供的Simulink模型文件,深入剖析Stribeck摩擦模块的数学实现与参数辨识方法,建议通过改变输入指令(如阶跃、正弦)和负载条件进行对比仿真,以直观理解非线性摩擦对系统动态特性的影响。

16,741

社区成员

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

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