我的程序中有一个高度很小,但长度很长的窗体,专门用来给用户显示一些信息用的.
怎样实现在该窗体上水平滚动的字幕啊?(文字是从最右边出来,从最左边移出去
,而且是无限循环的滚动-->就是说在最左边移出去的字马上在最右边有接上).在线等?
有不明白的地方请直接问!!

解决方案 »

  1.   

    这样吧:
      用 Timer 控件不断改变 Label 控件的 Left 值,这样 Label 看起来就像是在移动了。事实上,动画都是基于这个思想的!
      

  2.   

    在 Timer 中再检测 Label 的值,当它大于(或小于)你的窗体边缘值时,就把它改回初始状态!这样就可以循环了!
      

  3.   

    用abc里的控件。lmd 组件里也有。
    www.51delphi.com下
      

  4.   

    to:My_first
    如果不用控件呢?
    to: AV_15(C.C.Q.) ( 
    用 Timer 控件不断改变 Label 控件的 Left 值的方法我当然知道,只是这种方法不能把在左边移出去的文字显示到右边区;
    to myhfit()
     只有文字
      

  5.   

    那还不如用两个同样的 Label 在两侧同时进行.
      

  6.   

    AV_15(C.C.Q.) 的方法应该没有问题。
      

  7.   

    用两个label,设定为同样的文字.当lable1.left<0时,label2.top:=form1.widh,然后在timer的事件里,让这两个label都加一或几ok?
      

  8.   

    先检测lable.left的值,然后再改变,
      

  9.   

    for i:=0 to lable1.width do
    begin
      lable2.left:=lable2.left - 1 ;//左移一象素
      if i:=lable1.width then
        begin
          lable2.left:=lable1.width;
          i:=0;
        end;end;
      

  10.   

    //////////////////////////////////
    //CopyRght(C)Stanely 2002-8-20////
    //[email protected]///////////
    //////////////////////////////////unit ScrollingLabel_San;interface
    uses
    windows,sysutils,classes,extctrls,stdctrls,controls;type
      TScrollingLabel_San=class(TLabel)
      private
      protected
        Timer:TTimer;
        CurrentIndex:integer;
        TotalString:string;
        ShowAll:boolean;
        Spaces:integer;
        procedure ClearText;
        function AddSpaces(AStr:string;Count:integer):string;
        procedure OnTimer(Sender:TObject);
        function GetLastSpace:integer;
        function GetTextWidth:integer;
      public
        procedure SetString(AStr:string);
        function GetString:string;
        function IsGoing:boolean;
        function GetInterval:integer;
        procedure SetInterval(new:integer);
        procedure Start;
        procedure Pause;
        procedure Go;
        constructor Create(AOwner:TWinControl;AString:string;RefreshInterval:integer;StartNow:boolean=true);
        destructor Destroy;override;
      end;
    implementation{ TScrollingLabel_San }function TScrollingLabel_San.AddSpaces(AStr: string;
      Count: integer): string;
    var
    i:integer;
    begin
    result:=astr;
      for i:=1 to count do
      begin
        result:=result+' ';
      end;
    end;procedure TScrollingLabel_San.ClearText;
    begin
      canvas.FillRect(canvas.ClipRect);
    end;constructor TScrollingLabel_San.Create(AOwner: TWinControl;AString:string; RefreshInterval: integer; StartNow: boolean);
    begin
      inherited create(aowner);
      self.Alignment:=taRightJustify;
      //parent:=aowner;
      autosize:=false;
      width:=30;
      height:=18;
      timer:=ttimer.Create(self);
      timer.Interval:=refreshinterval;
      timer.OnTimer:=self.ontimer;
      timer.Enabled:=startnow;
      
      totalstring:=astring;  currentindex:=1;end;destructor TScrollingLabel_San.Destroy;
    begin
      timer.Free;
      inherited;
    end;function TScrollingLabel_San.GetInterval: integer;
    begin
      result:=timer.Interval;
    end;function TScrollingLabel_San.GetLastSpace: integer;
    var
    j,i:integer;
    begin
      j:=0;
      for i:=length(caption) downto 1 do
      begin
        if caption[i]<>' ' then break;
        inc(j);
      end;
      result:=j;
    end;function TScrollingLabel_San.GetString: string;
    begin
      result:=totalstring;
    end;function TScrollingLabel_San.GetTextWidth: integer;
    begin
      result:=canvas.TextWidth(copy(totalstring,currentindex,length(totalstring)));
    end;procedure TScrollingLabel_San.Go;
    begin
      timer.Enabled:=true;
    end;function TScrollingLabel_San.IsGoing: boolean;
    begin
      result:=timer.Enabled;
    end;procedure TScrollingLabel_San.OnTimer(Sender: TObject);
    var
    c:string;
    begin
         if currentindex>length(totalstring) then
         begin
           c:=addspaces('',self.GetLastSpace);
           if canvas.TextWidth(c)<clientwidth then
             caption:=caption+' '
           else
             currentindex:=1;  
         end
         else
         begin
            caption:=copy(totalstring,1,currentindex);
            inc(currentindex);
         end; 
    end;procedure TScrollingLabel_San.Pause;
    begin
      timer.Enabled:=false;
    end;procedure TScrollingLabel_San.SetInterval(new: integer);
    begin
      timer.Interval:=new;
    end;procedure TScrollingLabel_San.SetString(AStr: string);
    begin
      totalstring:=astr;
    end;procedure TScrollingLabel_San.Start;
    begin
      caption:='';
      currentindex:=1;
      timer.Enabled:=true;
    end;end.
    //使用很简单, public部分就那几个函数。
      

  11.   

    //对了,别忘了设置他的parent,否则不能显示!