2007. július 14., szombat

How to create a Typing Simulation in an about box


Problem/Question/Abstract:

In my about box, I'd like (when the about box window is shown) to start "typing" something (maybe in a paintbox). I mean, instead of showing some labels with the information, the program could start typing it by itself , maybe reading the information from an invisible memo on the same form and start writing it on the paintbox. For example, it could start writing letters one by one and making them sentences, also leave the spaces required and also show a graphic " | " after anything written (like in the edit controls). Could someone show some code of doing that? To better explain, I'd like to simulate the "typing" like someone is typing on the screen, leaving spaces, writing pauses, semicolons , etc.

Answer:

A way would be to put a timer on the aboutbox, and every timer click draw add an extra character. It may be best to use a TImage and draw the chars to the image. That way they will stay without needing a redraw. Here are the basic steps:

Include the text to type in a memo.

On create move the memo off screen (make invisible), set variables of say ml=memo, line=0, sp=string, position=-1, Xpos:= 0, Ypos:= 0, tmpstr:= ''

On a timer do


begin
  if (sp = -1) then
  begin
    ypos := ypos + image1.canvas.textheight('A');
    xpos := 0;
    tmpstr := memo1.lines[ml];
    Inc(ml);
    sp := 1;
  end;
  Image1.Canvas.TextOut(xpos, ypos, tmpstr[sp]);
  Inc(sp)
    xpos := xpos + image1.canvas.textwidth('A');
  if (sp > Length(TmpStr)) then
    sp := -1;
end;

Nincsenek megjegyzések:

Megjegyzés küldése