假如下述代码实现label的循环向上移动:
procedure TForm1.upMoveTimerTimer(Sender: TObject);
begin
  if label1.top>=label1.height+40 then //若尚未达到最上端
     begin
      label1.top:=label1.top-1;
      label1.caption:=str;
     end
  else
     label1.top:=form1.height-70;//底部位置
end;
那么,再添加一个nextTimer,实现label1.caption字符串内容的不断变换。即:当程序启动,label首先载入字符串并从底部上移,当判断达到顶部,就载入下一个不同的字符串再次从底部上移,如此不断循环。
本人鄙陋,操弄不好两个timer的关系。希望高手指点!

解决方案 »

  1.   

    这要两个timer做什么,一个就可以了。
    未到最上端,只要移动就可以了
    到了最上端就移动到底部,同时换字符串
      

  2.   

    我也是楼上的意见。
    StrList: TStringList;
    index: integer;
    StrList := TStringList.Create;
    index := 0;
    StrList.Items.Add('Aaaaaaaaaa');
    StrList.Items.Add('Bbbbbbbbbb');
    StrList.Items.Add('Cccccccccc');
    StrList.Items.Add('Dddddddddd');
    procedure TForm1.upMoveTimerTimer(Sender: TObject); 
    begin 
      if label1.top>=label1.height+40 then //若尚未达到最上端 
        begin 
          label1.top:=label1.top-1; 
          label1.caption:=str; 
        end 
      else
      begin 
        label1.top:=form1.height-70;//底部位置
         str := StrList.Items.Strings[index]; 
         inc(index);
        if index >= StrList.Count then index := 0;
      end;
    end; 
      

  3.   

    类似走马灯的……作为新手一个两个TIMER不是关键,能实现出来就可以。做好以后再慢慢优化……
      

  4.   

    现在我把我的整个程序贴出来供大家探讨:edit是为了便于观察另加的,每个文本文件或两行,或十几行不等
    var
      idx:shortint;
    function TForm1.ShowDifferentText(Num: shortint): widestring;
    var//自定义
      strlist:Tstringlist;
    begin
       case Num of
       1:begin
         strlist:=Tstringlist.Create ;
         strlist.LoadFromFile(extractFilepath(application.ExeName)
                     +'textf\a.txt');
         result:=strlist.Text ;
         strlist.Free ;
         end;
       2:begin
         strlist:=Tstringlist.Create ;
         strlist.LoadFromFile(extractFilepath(application.ExeName)
                     +'textf\b.txt');
        result:=strlist.Text ;
         strlist.Free ;
         end;
       3:begin
         strlist:=Tstringlist.Create ;
         strlist.LoadFromFile(extractFilepath(application.ExeName)
                     +'textf\c.txt');
         result:=strlist.Text ;
         strlist.Free ;
         end;
       4:begin
         strlist:=Tstringlist.Create ;
         strlist.LoadFromFile(extractFilepath(application.ExeName)
                     +'textf\d.txt');
         result:=strlist.Text ;
         strlist.Free ;
         end;
       end;
    end;
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      if label1.top>=label1.height+40 then
         label1.top:=label1.top-1
      else
       begin
         label1.top:=form1.height-70;
         label1.Caption := ShowDifferentText(idx);
         inc(idx);   edit1.Text :=inttostr(idx) ; //验证一下
         if idx>=4 then
            idx := 0;
       end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      timer1.Enabled :=true;
      label1.top:=self.height;
      label1.Font.Color :=clred;
      idx:=0;
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      timer1.Enabled :=false;
      timer1.Interval :=10;
      label1.Left :=200;
      label1.Width :=360;
      label1.Height:=350;
      label1.Transparent:=true;
      label1.Parent.DoubleBuffered :=true;
    end;
    可以实现上移再返回底部时加载另外一个文件。但存在问题是:1.当idx为1时,不出现label ,最终只循环显示3个文件 2.上移到顶部(又返回)的位置与文件的行数有关。行数越多,上移位置越低。而我希望每次上移都到窗体顶部才返回底部!
    我是菜鸟一个,请高人们完善这个程序!
      

  5.   


    procedure TForm1.upMoveTimerTimer(Sender: TObject); 
    begin 
      if 未到达顶端 then //若尚未达到最上端 
        begin 
          ...
          label1.caption:='未到达顶端'; 
        end 
      else //到达顶端
      begin
        label1.caption:='到达顶端';
        ...
      end;
    end; 
      

  6.   

    一个timer就可以完成,如果非需要两个,就在每个time事件的第一句加判断,不然会造成程序假死,timer只是一个独立消息处理,并不是多线程,请注意!