📄 l_edit中自做动态显示的控件.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Welcome to Delphi Tips !</title>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<link rel="stylesheet" href="../tips.css"></head>
<body text="#675350">
<div align="left">
<table border="1" cellpadding="0" cellspacing="0" width="579" height="63" bordercolorlight="#784400" bordercolordark="#D8D0C8">
<tr>
<td width="194" height="86"><img src="../images/title.gif" width="340" height="85"></td>
<td width="377" height="86" valign="top"><img src="../images/dong.jpg" width="251" height="85">
</td>
</tr>
</table>
<br>
</div>
<div align="left">
<table border="1" cellpadding="0" cellspacing="0" width="578" height="18" bordercolorlight="#784400" bordercolordark="#CCCCCC" class="p2">
<tr bgcolor="#B0A498">
<td width="574" height="18"> ><a href="../index.htm">DelphiTips首页</a>
> <a href="main.htm">控件应用</a></td>
</tr>
</table>
<br>
<table width="96%" border="1" bordercolorlight="#784400" cellspacing="0" bordercolordark="#D8D0C8">
<tr bgcolor="#B0A498" class="p1">
<td colspan="3" height="18">
<div align="center">Delphi 中自做动态显示的控件</div>
</td>
<td width="12%" class="p2" height="18"><<<a href="003.htm">上一篇</a></td>
<td width="13%" class="p2" height="18"><a href="005.htm">下一篇</a>>></td>
</tr>
<tr class="p2">
<td colspan="5">
<table width="100%" border="0" class="p2">
<tr>
<td width="3%"> </td>
<td width="94%">
<p><span style="font-size: 9pt"><font color="#ffffff">----</font>
Delphi以其优秀的界面和简单的用法深受广大程序员的喜爱.笔者经过摸索,自做了一个具有动态显示特性的控件。只需在主程序中调用该控件的一个方法即可实现动态显示。在动态显示的同时,为了不影响主程序做其他的事情,笔者采用了比较流行的线程技术。
</span></p>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font>
<b>一. 方案</b> </span></p>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font>
自做一个父类为TEdit的控件,应该有一个Text属性,能自由地输入要动态显示的内容; 并且有一个MoveShow方法,使的Text的内容能动态的显示。在主程序中创建一个线程,启动线程时,调用该控件的MoveShow方法。
</span></p>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font>
<b>二. 制作控件</b> </span></p>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font>
启动New Component,选Tedit为父类,建立L_Tedit1类,并创建L_edit.pas. 再编写L_edit.pas
如下: </span></p>
<pre><span style="font-size: 9pt">unit L_Edit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs,
StdCtrls;
type
L_TEdit1 = class(TEdit)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent); override;
procedure MoveShow;
published
{ Published declarations }
property Text;
end;
procedure Register;
implementation
constructor L_TEdit1.Create(AOwner:TComponent);
begin
inherited create(aowner);
color:=clblue;
font.Color:=clyellow;
font.Size:=12;
font.Name:= '@仿宋_GB2312';
tabstop:=false;
update;
end;
procedure L_TEdit1.MoveShow;
var
edit_length,i:integer;
edit_char:char;
chars: string;
begin
chars:='';
if (length(text)=0) then
text:=’Welcom you to use the software!’;
edit_length:=length(text);
for i:=1 to edit_length do
begin
edit_char:=text[1];
if (Ord(edit_char) >127) then
if length(chars) >1 then
begin
text:=copy(text,2,edit_length-2)+chars;
chars:='';
end
else
begin
chars:=copy(text,1,2);
text:=copy(text,2,edit_length-1);
end
else
begin
text:=copy(text,2,edit_length-1)+edit_char;
end;
update;
sleep(100);
end;
end;
procedure Register;
begin
RegisterComponents('Samples', [L_TEdit1]);
end;
end.
再保存该文件。</span></pre>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font>
启动Image Editor 创建L_Edit.dcr , 选New- >Bitmap,自己做一个图标,保存名为L_TEDIT1(与新建的类同名)。注意L_Edit.dcr
与L_Edit.pas 要在同一个目录中(缺省为\delphi\lib目录中。再单击Install Component. 选Into
new package属性页,填上L_Edit.pas 的路径和文件名,并在该路径下新建L_Edit1.dpk 文件。之后一直单击OK即可。此时我们可以在Delphi
的工具栏Sample 一项中看到自己创建的图标。 </span></p>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font>
<b>三. 编写主程序</b> </span></p>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font>
在主窗体Form1中放一自己创建的控件,在Text的属性中填上要显示的文字(中英文都可)。与该窗体对应的L_unit1.pas内容如下:
</span></p>
<pre><span style="font-size: 9pt">unit L_Unit1;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
StdCtrls, L_Edit;
type
Tmythread=class(TThread)
protected
procedure Execute; override;
end;
TForm1 = class(TForm)
L_TEdit11: L_TEdit1;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MyThread1:TMyThread;
implementation
{$R *.DFM}
Procedure TMyThread.Execute;
begin
while true do form1.L_TEdit11.MoveShow;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyThread1:=TMyThread.Create(false);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage('Welcome You!');
end;
end.</span></pre>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font>
该程序在Delphi4.0 for win95 下编译运行通过。 </span></p>
</td>
<td width="3%"> </td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#B0A498" class="p2">
<td height="22" width="61%" colspan="2"> <marquee behavior="alternate">如果你有什么好的资料,可以寄给我哟:)</marquee></td>
<td height="22" width="14%"><a href="../index.htm"><<回到首页</a></td>
<td height="22" width="12%"><<<a href="003.htm">上一篇</a></td>
<td height="22" width="13%"><a href="005.htm">下一篇</a>>></td>
</tr>
</table>
<br>
<br>
<hr size=1 noshade width=500>
<table width="75%" border="0" align="center" class="p2">
<tr>
<td colspan="2"> </td>
<td width="24%">
<table width="95%" border="1" bordercolorlight="#663300" bordercolordark="#CCCCCC" cellspacing="0" class="p2">
<tr>
<td>
<div align="center">Delphi 技巧集</div>
</td>
</tr>
</table>
</td>
<td width="38%"> </td>
</tr>
<tr>
<td width="16%"> </td>
<td colspan="2">Copyright 1999.11 by 东子</td>
<td width="38%"><a href="../jintongbao@188.net">Mail to me!</a></td>
</tr>
<tr>
<td colspan="4">
<div align="center">感谢广州视窗提供主页空间</div>
</td>
</tr>
</table>
<br>
</div><div align="center"><center>
</center></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -