可不向Lovefox说的那么简单,下面是一个练习:
unit UShowText;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, jpeg, ComCtrls, Buttons ;
type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
Button2: TButton;
TrackBar1: TTrackBar;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
BitBtn1: TBitBtn;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
private
procedure zShowText;
procedure zSetLineHeight;
procedure zBmpCreate;
procedure zSetBmp;
procedure zShowLine(sender :TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
const
bWidth=200;
var
bmp :TBitMap;
sItem:TStringList;
iDc :HDC;
LineHeight,Currline:integer;
R1,bRect :TRect;
procedure TForm1.zShowText;
var j:integer;
begin
sItem:=TStringList.Create;
with sItem do
begin
for j:=1 to 12 do
begin
add('序号:'+inttostr(j)+' 这是第'+Inttostr(j)+'行');
end;
add('----------#@######---------------');
add('共有'+IntToStr(j-1)+'行');
end;
zBmpCreate;
sitem.Free;
end;
procedure TForm1.zShowLine(sender :TObject);
begin
zShowText;
end;
procedure Tform1.zBmpCreate;
var
i,y:integer;
begin
if bmp<>nil then bmp.free;
bmp:=TBitMap.Create;
// bmp.LoadFromFile('g:abc.bmp');
zSetBmp;
R1.Right:=bRect.Right;
R1.Bottom :=bRect.Bottom;
y:=Panel1.Height-100;
for i:=0 to sItem.Count-1 do
begin
R1.Top:=y;
R1.Bottom :=R1.top+LineHeight;
DrawText(bmp.Canvas.handle,pChar(sItem),-1,R1,dt_center or Dt_TOP);
Inc(y,LineHeight);
end;
end;
procedure TForm1.zSetBmp;
begin
zSetLineHeight;
With bRect do
begin
Top :=0;
Left :=0;
Right:=panel1.Width-2;
Bottom:=LineHeight*sItem.Count+Height;
end;
with Bmp do
begin
Height:=bRect.Bottom;
Width :=bRect.Right-7;
With Canvas do
begin
Font:=self.font;
font.Color :=Rgb(245,235,20);
Brush.Color:=clBlack;
FillRect(bRect);
Brush.Style:=bsClear;
end;
end;
end;
procedure TForm1.zSetLineHeight;
var
Metrics :TTextMetric;
begin
GetTextMetrics(iDc,Metrics);
LineHeight :=Metrics.tmHeight+Metrics.tmInternalLeading;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
label3.Caption :='间隔'#13'时间';
Label4.Caption :='100';
// idc:=Image1.Canvas.Handle;
iDC:=GetDc(Panel1.Handle);
Currline:=0;//LineHeight;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if bmp<>nil then bmp.free;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
zShowLine(self);
BitBlt(iDc,7,50,Panel1.Width-14,Panel1.Height-100,
bmp.canvas.Handle,0,Currline,srcCopy);
Inc(Currline,1);//LineHeight);
if Currline>=bRect.Bottom-panel1.Height+200 then
begin
timer1.Enabled :=false;
Currline:=0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled:=not Timer1.Enabled;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.Enabled :=false;
Currline:=0;//LineHeight;
button1.Click;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
Timer1.Interval:=TrackBar1.Position*5;
Label4.Caption :=inttostr(Timer1.Interval);
end;
end