利用textrect函数
textrect(rect:trect;x,y:integer;const text:string)
文本字符串超出矩形区域,将超出的部分截去。
通过不断改变输出矩形框的大小,使输出字符串一段一段显示出来
type
tform1=class(Tform)
backimage:timage;
timer1:ttimer;
private
maindir:string;
nowstep:integer;
procedure tform1.formcreate(sender:Tobject);
begin
maindir :=ExtractFilePath(ParamStr(0));
backimage.picture.loadfromfile(maindir+'......');
backimage.canvas.font.name:='楷体_GB2312';
backimage.canvas.font.size:=36;
backimage.canvas.font..stule:=[fsbold];
nowstep:=0;
end;
const maxstep=40;
procedure tform1.timer1timer(sender:Tobject);
var
x0,y0:integer;
outputstring:string
w:integer;
begin
x0:=10;
y0:=10;
outputstring:='卡拉OK字幕效果示例‘;
if nowstep=0 then
begin
backimage.canvas.brush.style:=bsclear;
backimage.canvas.font.color:=clblack;
//原色
backimage.canvas.textout(x0,y0,outputstring);
end
else
begin
backimage.canvas.brush.style:=bsclear;
backimage.canvas.font.color:=clred;
//效果色
w:=backimage.canvas.textwidth(outputstring);
backimage.canvas.textrect(rect(x0,y0,x0+w*nowstep div maxstep,y0+backimage.canvas..textheight(outputstring)),x0,y0,outputstring);
end;
inc(nowstep);
if nowstep>maxstep then
nowstep:=0;
end;