在窗体中怎样实现字体滚动?

解决方案 »

  1.   

    有很多方法,简单的是用一个Timer控制Label,定时让其Left := Left + 1,若超过再设其初值,这种方法不太好,有明显的抖动现象。
    一个好的方法是,用Image来显示,再Image上用Canvas画字,下面贴一些代码:
    var
      Form1: TForm1;
      x, tt, l, h: integer;
      pic: Trect;
      map: Tbitmap;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      x := x - 1;
      tt := tt - 1;
      if x < -160 then
        x := image1.height + 20;
      tt := x + 80;
      image1.Canvas.font.size := 18;
      image1.Canvas.font.color := clLime;
      image1.Canvas.TextOut(10,x,'OK 字 幕 移 动 演 示');
      image1.Canvas.font.size:=12;
      image1.Canvas.font.color:= clLime;
      image1.Canvas.TextOut(20,x+50,' 字 体 变 色 效 果 演 示');
      l:=image1.Canvas.textwidth(' 字 体 变 色 效 果 演 示');
      h:=image1.Canvas.textheight(' 字 体 变 色 效 果 演 示');
      image1.Canvas.pen.color:=clGreen;
      image1.Canvas.moveto(20,h+x+50-2);
      image1.Canvas.lineto(20+l,h+x+50-2);
      pic.topleft.x:=30;
      pic.topleft.y:=tt;
      pic.bottomright.x:=pic.topleft.x+100;
      pic.bottomright.y:=pic.topleft.y+80;
      image1.canvas.stretchdraw(pic,map);
      image1.Canvas.pen.color:=clBlack;
      image1.Canvas.moveto(0,pic.topleft.y+80);
      image1.Canvas.lineto(pic.topleft.x+100,pic.topleft.y+80);
    end;
    { 以下设置动画初值}
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      timer1.enabled:=true;
      timer1.Interval:=25;
      x:=image1.height+20;
      tt:=x+80;
      form1.repaint;
      image1.Canvas.brush.color:=clBlack;
      pic:=Rect(0,0,image1.width,image1.height);
      image1.Canvas.FillRect(pic);
      pic:=Rect(-1,-1,1,1);
      map:=Tbitmap.create;
      map.loadfromfile('d:\\t.bmp');
      image1.canvas.stretchdraw(pic,map);
    end;
      

  2.   

    大把方法.
    timer+label
    字符串控制.