Title: How to show a text progressiv as typed with a typewriter (horizontal/vertical)
procedure VerticalTypewriter(text: string; image: timage; delay: integer);
var
x,y,i: integer;
begin
image.Canvas.Refresh;
application.ProcessMessages;
y := 1;
for i := 1 to length(text) do begin
application.ProcessMessages;
y := y+image.Canvas.TextHeight(text[i]);
x := image.width div 2 - (image.Canvas.TextWidth(text[i]) div 2);
image.Canvas.TextOut(x,y,text[i]);
sleep(delay);
end;
end;
// Horizontal Typewriter ( , , , )
procedure HorizontalTypewriter(text: string; image: timage; delay, space: integer);
var
x,y,i: integer;
begin
image.Canvas.Refresh;
application.ProcessMessages;
x := 1;
for i := 1 to length(text) do begin
application.ProcessMessages;
y := image.Picture.Height div 2 - (image.Canvas.TextHeight(text[i]) div 2);
x := x+image.Canvas.TextWidth(text[i])+space;
image.Canvas.TextOut(x,y,text[i]);
sleep(delay);
end;
end;
// Sample calls:
procedure TForm1.Button1Click(Sender: TObject);
begin
//
VerticalTypewriter('HELLO BIG-X', image1, 100 );
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//
HorizontalTypewriter('Hello Big-X', image2, 100, 1 );
end;
/space/delay/image/text/delay/image/text/space/time/image/text