求助:自己继承TPaintBox写的winform 控件实时刷新,刷新的时

控件的前后显示解决办法 - C++ Builder当前位置:& &&&控件的前后显示解决办法控件的前后显示解决办法www.MyException.Cn&&网友分享于:&&浏览:19次控件的前后显示paintbox怎么显示在chart前面,不是放在chart里面,我在paintbox上画东西会被chart挡住,所以要放在前面sendtoback 和BringToFront是不行的 试过了------解决方案--------------------
TPaintBox 继承自 TGraphicControl, 而 TChart 继承自 TWinControl, 继承自 TGraphicControl 的控件是不能放在继承自 TWinControl 的控件的前面的.
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有拒绝访问 | www.wangchao.net.cn | 百度云加速
请打开cookies.
此网站 (www.wangchao.net.cn) 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(3f51eebe41644cc0-ua98).
重新安装浏览器,或使用别的浏览器下次自动登录
现在的位置:
& 综合 & 正文
继承 TPaintBox 实现信息发布滚屏显示控件
//------------------------------------------------------------------------------------------------------------
// unit_ScrollDrawText.cpp
//---------------------------------------------------------------------------
#include &vcl.h&
#pragma hdrstop
#include "unit_ScrollDrawText.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
static inline void ValidCtrCheck(TScrollDrawText *)
new TScrollDrawText(NULL);
//---------------------------------------------------------------------------
namespace Unit_scrolldrawtext
void __fastcall PACKAGE Register()
TComponentClass classes[1] = {__classid(TScrollDrawText)};
RegisterComponents("My Component", classes, 0);
//---------------------------------------------------------------------------
__fastcall TScrollDrawText::TScrollDrawText(TComponent* Owner)
: TPaintBox(Owner)
SourceStringList = new TStringL
// 初始化来源字符串列表
ReleaseStringList = new TStringL // 初始化发布列表
ShowControl = new TShowControl(true); // 初始化多线程控制
OutTextWidth = 20; // 设定默认行宽
//---------------------------------------------------------------------------
__fastcall TScrollDrawText::~TScrollDrawText()
ShowControl-&Done(); // 设置关闭标记
InitReleaseStringList(); //
InitSourceStringList(); // 清空 StringList 对象
delete SourceStringL
delete ReleaseStringL
delete ShowC
//---------------------------------------------------------------------------
void __fastcall TScrollDrawText::InitSourceStringList()
for ( int i = 0; i & SourceStringList-&C i++)
if ( SourceStringList-&Objects[i] != NULL )
delete (TFont*)SourceStringList-&Objects[i]; // 删除表内 TFont 对象
SourceStringList-&Objects[i] = NULL;
SourceStringList-&Clear();
//---------------------------------------------------------------------------
void __fastcall TScrollDrawText::InitReleaseStringList()
// 发布字符串的对象指针全部来自 SourceStringList
// 清除指针对象只需要由 SourceStringList 完成即可
ReleaseStringList-&Clear();
//---------------------------------------------------------------------------
void __fastcall TScrollDrawText::AddString(const String InsertString, const TColor Color)
// 插入数据,也就是外部接口之一
TFont* Font = new TF // 创建一个对象用于保存字体信息
Font-&Charset = DEFAULT_CHARSET;
Font-&Color = C
Font-&Name = "宋体";
Font-&Size = 10;
SourceStringList-&AddObject(InsertString, Font);
ReBuileReleaseStringList(); // 重新构建布字符串
//---------------------------------------------------------------------------
void __fastcall TScrollDrawText::ReBuileReleaseStringList()
// 新字符串进入,先清空发布字符串
// 重新往原字符串中添加
InitReleaseStringList();
for (int i = 0; i & SourceStringList-&C i++)
CutInsertString
SourceStringList-&Strings[i],
ReleaseStringList,
SourceStringList-&Objects[i]
/*CutInsertString // 每行插入一个回车符
ReleaseStringList,
SourceStringList-&Objects[i]
//---------------------------------------------------------------------------
void __fastcall TScrollDrawText::CutInsertString
(const String InsertString, TStringList* ReleaseStringList, TObject* Object)
// 裁剪来源字符串达到额定宽度,再插入发布字符串
WideString wdStr = InsertS
if ( wdStr.Length() &= 0 )
String NewString = "";
for ( int Index = 1; ; Index++ ) // 搜索字符串,将每个字符追加到 wdStr
// 单字符累加,双字节由 WideString 自动处理
NewString = NewString + wdStr.SubString( Index, 1 );
if ( NewString == "" || NewString == NULL ) // 字符不存在
if ( Index == ( InsertString.Length() ) ) // 循环出口,最后一个字符串
ReleaseStringList-&AddObject(NewString, Object);
NewString = "";
else if ( NewString.Length() &= OutTextWidth ) // 个字节一行,将进来的字符串分行
ReleaseStringList-&AddObject ( NewString, Object ); // 向发布字符串输入新的对象
NewString = "";
//---------------------------------------------------------------------------
void __fastcall TScrollDrawText::Suspend()
ShowControl-&Suspend(); // 启动多线程
//---------------------------------------------------------------------------
bool __fastcall TScrollDrawText::Suspended()
return ShowControl-&S // 察看多线程状态
//---------------------------------------------------------------------------
void __fastcall TScrollDrawText::Resume()
/*String temp = "";
for ( int i = 0; i & ReleaseStringList-&C i++ ) // 测试代码
temp = ReleaseStringList-&Strings[i];
ShowControl-&SetScreenText(this, ReleaseStringList); // 设置输出宽度
ShowControl-&Resume(); // 开始滚动运行
//---------------------------------------------------------------------------
void __fastcall TScrollDrawText::SetScrollSpeed(const int ScrollSpeed)
ShowControl-&SetScrollSpeed(ScrollSpeed); // 设置速度 20~100 为宜
//---------------------------------------------------------------------------
void __fastcall TScrollDrawText::SetOutTextWidth(const int OutTextWidth)
this-&OutTextWidth = OutTextW // 设置宽度
ShowControl-&Suspend();
ReBuileReleaseStringList();
// 重新根据宽度生成发布字符串
ShowControl-&Resume();
//---------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------
// unit_ScrollDrawText.h
//---------------------------------------------------------------------------
#ifndef unit_ScrollDrawTextH
#define unit_ScrollDrawTextH
//---------------------------------------------------------------------------
#include &SysUtils.hpp&
#include &Classes.hpp&
#include &Controls.hpp&
#include &ExtCtrls.hpp&
//---------------------------------------------------------------------------
#include "unit_ShowControl.h"
//---------------------------------------------------------------------------
class PACKAGE TScrollDrawText : public TPaintBox
__published:
void __fastcall AddString(const String InsertString, const TColor Color);
void __fastcall Resume();
void __fastcall Suspend();
bool __fastcall Suspended();
void __fastcall SetScrollSpeed(const int ScrollSpeed);
void __fastcall SetOutTextWidth(const int OutTextWidth);
TStringList* SourceStringL // 近来的字符串列
TStringList* ReleaseStringL // 过滤后的字符串列
int OutTextW // 输入宽度字节数
TShowControl* ShowC // 多线程控制器
void __fastcall CutInsertString
(const String InsertString, TStringList* ReleaseStringList, TObject* Object);
void __fastcall InitSourceStringList();
void __fastcall InitReleaseStringList();
void __fastcall ReBuileReleaseStringList();
protected:
__fastcall TScrollDrawText(TComponent* Owner);
__fastcall ~TScrollDrawText();
//---------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
// unit_ShowControl.cpp
//---------------------------------------------------------------------------
#include &vcl.h&
#pragma hdrstop
#include "unit_ShowControl.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
Important: Methods and properties of objects in VCL can only be
used in a method called using Synchronize, for example:
Synchronize(&UpdateCaption);
where UpdateCaption could look like:
void __fastcall TShowControl::UpdateCaption()
Form1-&Caption = "Updated in a thread";
//---------------------------------------------------------------------------
__fastcall TShowControl::TShowControl(bool CreateSuspended)
: TThread(CreateSuspended)
ScrollSpeed = 20; // 默认微秒每像素滚动
pBitmap = new Graphics::TBitmap(); // 创建缓冲区
//---------------------------------------------------------------------------
void __fastcall TShowControl::Execute()
//---- Place thread code here ----
//---------------------------------------------------------------------------
__fastcall TShowControl::~TShowControl()
delete pB // 释放缓冲区
//---------------------------------------------------------------------------
void __fastcall TShowControl::SetScreenText(TPaintBox* Image, TStringList* StringList)
ScreenImage = I // ScreenImage 指针指向窗体上的 Image
this-&StringList = StringL // 指向处理好可以发布的字符串
if ( pBitmap-&Canvas-&LockCount == 0 )
// 设置缓冲区尺寸
pBitmap-&Canvas-&Lock();
pBitmap-&Height = Image-&H
pBitmap-&Width = Image-&W
pBitmap-&Canvas-&Unlock();
//---------------------------------------------------------------------------
void __fastcall TShowControl::Done()
OnClose = // 关闭标记
//---------------------------------------------------------------------------
inline void __fastcall TShowControl::Drow()
// 对显示区进行 Draw 操作
if ( ScreenImage-&Canvas-&LockCount == 0 )
ScreenImage-&Canvas-&Lock();
ScreenImage-&Canvas-&Draw(0,0,pBitmap);
ScreenImage-&Canvas-&Unlock();
//---------------------------------------------------------------------------
void __fastcall TShowControl::Go()
const int RowHeight = 20; // 设定行高
const LeftSpace = 4; // 设定左间距
for ( int OutLine = pBitmap-&Height * (1-0.618) ; OutLine &= - RowH OutLine -- )
// 循环条件描述, height*(1-0.618) 为起始位置,-20为回滚位置
if ( OnClose ) // 判断是否关闭
Synchronize(&InitImage); // 初始化 Bitmap
for (int ChildIndex = 0; ChildIndex & StringList-&C ChildIndex ++ )
if ( pBitmap-&Canvas-&LockCount == 0 )
pBitmap-&Canvas-&Lock();
/*if ( StringList-&Objects[ChildIndex] != NULL )
pBitmap-&Canvas-&Font-&Assign((TFont*)StringList-&Objects[ChildIndex]);
// 对缓冲区输出内容
pBitmap-&Canvas-&Font-&Assign((TFont*)StringList-&Objects[ChildIndex]);
pBitmap-&Canvas-&TextOutA (
LeftSpace, OutLine + ChildIndex * RowHeight , StringList-&Strings[ChildIndex]);
// 左边距,高度,内容
pBitmap-&Canvas-&Unlock();
if ( ChildIndex * RowHeight & pBitmap-&Height )
// 发布行数过多不对其进行绘画,只需超过 Height 即可
Synchronize(&Drow); // 缓冲区输出到显示区
//pBitmap-&SaveToFile("jjj.bmp"); // 作为测试
if ( GetSleep() == -1 ) // 设置滚动速度,同时侦测是否需要退出
if ( OutLine == - RowHeight ) // 回滚控制,当升至顶端 -20 的位置,把 0 移动到 最后
StringList-&AddObject(StringList-&Strings[0],StringList-&Objects[0]); // 复制 0 至末尾
StringList-&Delete(0); // 删除 0
OutLine = 0 ; // 总体位置回移 20 个像素
//---------------------------------------------------------------------------
inline int __fastcall TShowControl::GetSleep()
int ScrollSpeedTemp = ScrollS
while ( ScrollSpeedTemp & 0 ) // 作为封闭循环的调处条件
if ( OnClose ) // 但完成标记为真
return -1;
Sleep(1); // 延时
ScrollSpeedTemp --;
//---------------------------------------------------------------------------
inline void __fastcall TShowControl::InitImage()
// 初始化缓冲区
if ( pBitmap-&Canvas-&LockCount == 0 )
pBitmap-&Canvas-&Lock();
pBitmap-&Canvas-&Brush-&Style = bsC
pBitmap-&Canvas-&Brush-&Color = clW
pBitmap-&Canvas-&FillRect(TRect(0, 0, pBitmap-&Width, pBitmap-&Height));
pBitmap-&Canvas-&Unlock();
//---------------------------------------------------------------------------
void __fastcall TShowControl::SetScrollSpeed(int ScrollSpeed)
// 设置滚动速度
this-&ScrollSpeed = ScrollS
//---------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// ShowControl.h
//-------------------------------------------------------------------------------------------------------
#ifndef unit_ShowControlH
#define unit_ShowControlH
//---------------------------------------------------------------------------
#include &Classes.hpp&
//---------------------------------------------------------------------------
class TShowControl : public TThread
Graphics::TBitmap *pB // 缓冲
TPaintBox* ScreenI // 来源
TStringList* StringL
int ScrollS // 默认微秒每像素滚动
inline int __fastcall GetSleep();
inline void __fastcall Drow();
void __fastcall Go();
inline void __fastcall InitImage();
protected:
void __fastcall Execute();
__fastcall TShowControl(bool CreateSuspended);
__fastcall ~TShowControl();
void __fastcall SetScreenText(TPaintBox* Image, TStringList* StringList);
void __fastcall Done();
void __fastcall SetScrollSpeed(int ScrollSpeed);
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
// 使用示范
//---------------------------------------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
LabeledEdit1-&Text = 20;
LabeledEdit2-&Text = 20;
ScrollDrawText1-&AddString("This is new message 1", clGreen);
ScrollDrawText1-&AddString("This is new message 2", clBlue);
ScrollDrawText1-&AddString("This is new message 3", clBlack);
ScrollDrawText1-&AddString("This is new message 4", clSkyBlue);
ScrollDrawText1-&AddString("This is new message 5", clYellow);
ScrollDrawText1-&AddString("This is new message 6", clTeal);
ScrollDrawText1-&AddString("This is new message 7", clPurple);
ScrollDrawText1-&AddString("This is new message 8", clAqua);
ScrollDrawText1-&AddString("This is new message 9", clSkyBlue);
ScrollDrawText1-&AddString("This is new message 0", clHotLight);
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
ScrollDrawText1-&AddString(LabeledEdit3-&Text, clHotLight);
ScrollDrawText1-&Resume();
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
ScrollDrawText1-&SetScrollSpeed(LabeledEdit1-&Text.ToInt());
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
ScrollDrawText1-&SetOutTextWidth(LabeledEdit2-&Text.ToInt());
//---------------------------------------------------------------------------
【上篇】【下篇】您所在位置: &
&nbsp&&nbsp&nbsp&&nbsp
Delphi 程序设计 课件 第十章 图形图像程序设计.pdf 20页
本文档一共被下载:
次 ,您可全文免费在线阅读后下载本文档。
下载提示
1.本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。
2.该文档所得收入(下载+内容+预览三)归上传者、原创者。
3.登录后可充值,立即自动返金币,充值渠道很便利
你可能关注的文档:
··········
··········
高等学校计算机基础教育规划教材
Delphi程序设计
第10章 图形图像程序设计
?了解Delphi 中图形图像处理控件及其在应用程序中的作用
?掌握图形图像处理控件的使用方法
?掌握绘制图形图像的对象和方法
?掌握利用Delphi 7实现图形绘制,图像处理的程序设计方法与技巧
Delphi 7 在图形图像制作和处理方面有着强大的支持功能,它提供了很多绘制图
形图像的对象和方法。本章主要介绍Delphi 中图形图像处理控件的使用,讲述
Delphi 7 中绘制和处理图形图像所需的基本对象和基本方法,以及这些对象和方
法的使用技巧,并将通过实例来进一步应用这些对象的属性和方法。
高等学校计算机基础教育规划教材
Delphi程序设计
10.1 图形图像基本控件
Delphi 7 为用户提供了丰富的图形图像处理功能,本节主要介绍Image 控件、
Shape控件和PaintBox 控件的使用方法。
10.1.1 Image 控件
Image 控件也称为图像控件,功能是用来显示图形文件,同时Image 控件也是一个
容器控件。该控件在【Additional 】选项卡上,类名为Timage 。
Image 控件的常用属性如表10.1所列。
表10.1 Image 控件的常用属性
该属性决定控件的尺寸是否随所显示的图像大小而改变
该属性返回可随意绘画的画布对象,用来修饰图像
该属性用来指定所要显示的图像文件,文件可以是位图(.bmp)、图标(.ico)或图
该属性用来控制所显示的图像是否可以随着控件的大小而进行拉伸变化
对于Image 控件Picture 属性,可以通过属性窗口设置,也可以在代码中设置,
image1.Picture.loadfromfile('f:\pic\abc.bmp');
高等学校计算机基础教育规划教材
Delphi程序设计
10.1.2 Shape 控件
Shape 控件可以用来绘制矩形、正方形、椭圆、圆、圆角矩形及圆角正方形。Shape
控件在【Additional 】选项卡中,类名为TShape 。
Shape 控件的常用属性如表10.2所列。
表10.2 Shape 控件的常用属性
该属性用来设置图形的填充样式和填充颜色
该属性用来设置图形的边框颜色、线条宽度和线型
该属性用来设置图形的形状,具体有cstCircle(圆形)、stEllipse(椭圆形)、
stRectangle(矩形)、stRoundRect(圆角矩形)、stSquare(正方形)和
stRoundSquare(圆角正方形)等属性值
10.1.3 PaintBox 控件
PaintBox 控件又称为绘图板控件,在应用程序中可以使用该控件来绘制图形。该控件
在【System】选项卡中,类名为TpaintBox 。
使用PaintBox控件绘制图形时,首先把控件添加到窗体上,然后利用属性对象Canvas
的属性与方法在绘图板上绘制图形或载入图像文件。如果要重画图形,可使用它的
Repaint方法清除已绘制的图形。
提示:PaintBox 控件上的图形都是以控件的左上角为原点坐标。
高等学校计算机基础教育规划教材
Delphi程序设计
【例10.1】 编写程序,实现3幅图片轮换显示。
操作步骤如下:
(1)新建工程,并完成窗体设计:在窗体上添加PaintBox 控件(PaintBox1)和Timer 控件
(Timer1),如图10.1所示。在‘f:\pic\’
正在加载中,请稍后...

我要回帖

更多关于 ios控件继承关系 的文章

 

随机推荐