使用Delphi实现文字滚动显示效果,主要是用Timer控制Label的位置实现,但是文字显示有闪烁,请高手指点如何消除闪烁!

解决方案 »

  1.   

    在Form上放个button,再放个Timer,添加下面代码:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Timer1: TTimer;
        procedure Button1Click(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      ABmp: TBitmap;
      Y:integer;
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      ABmp := TBitmap.Create;
      ABmp.Width := 200;
      ABmp.Height := 20;
      ABmp.Canvas.Brush.Color := Self.Color;
      ABmp.Canvas.FillRect(Rect(0,0,300,20));
      ABmp.Canvas.TextOut(1,1,'只要不是286,我是不会闪的!');
      Timer1.Interval := 1;
      Timer1.Enabled := True;
      Y := 200;
      Button1.Enabled := False;
    end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      ABmp.Free;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      if Y < 10 then 
        Y := 200
      else
        Y := Y - 1;
      BitBlt(Canvas.Handle,10,y,160,20,ABmp.Canvas.Handle,0,0,SRCCOPY);
    end;end.