试试吧,效果还可以。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
Button1: TButton;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
BMP,Buf : TBitmap;
PP : TPoint;
Text : String;
SS : TSize;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
PP := Point(10,10);
BMP := TBitMap.Create;
Buf := TBitmap.Create;
BMP.LoadFromFile('c:/1.bmp');
Buf.Width := BMP.Width;
Buf.Height := BMP.height;
Buf.Canvas.Draw(0,0,BMP);
with Buf.Canvas do begin
Font.Color := clRed;
Font.Name := '宋体';
Font.Size := 20;
Brush.Style := bsClear;
end;
Text := '大富翁论坛欢迎大家!';
SS := Buf.Canvas.TextExtent(Text);
PaintBox1.Canvas.CopyMode := cmSrcCopy ;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
BMP.Free;
Buf.Free;
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
PaintBox1.Canvas.Draw(0,0,Buf);
// PaintBox1.Canvas.CopyRect(RECT(PP.X,PP.Y,PP.X + SS.cx,PP.Y + SS.cy),Buf.Canvas,RECT(PP.X,PP.Y,PP.X + SS.cx,PP.Y + SS.cy));
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Buf.Canvas.CopyRect(RECT(PP.X,PP.Y,PP.X + SS.cx,PP.Y + SS.cy),BMP.Canvas,RECT(PP.X,PP.Y,PP.X + SS.cx,PP.Y + SS.cy));
Inc(PP.X);
Buf.Canvas.TextOut(PP.X,PP.Y,Text);
PaintBox1.Refresh;
end;
end.