在FORM上按任意键,界面一个数字累加滚动,再按任意键数字停止滚动,如何实现?请教高手!

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    var
      Add:boolean=false;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Add:=not Add;
      while add do
      begin
      application.ProcessMessages;
      sleep(50);
      edit1.Text:=inttostr(strtoint(edit1.Text)+1);
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     edit1.Text:='0';
    end;end.
      

  2.   

    procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      if Edit1.Text = '' then Edit1.Text := '0';
      Edit1.Text := IntToStr(StrToInt(Edit1.Text) + 1);  
      Sleep(20);  
      Application.rocessMessages;
      
    end;
      

  3.   

    用一个timer 控件不就行了吗!
      

  4.   

    在TForm的OnKeyDonw事件里写代码
      

  5.   

    procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      IsAdd:=not IsAdd; //布尔型全局变量初始值置False
      while add do
      begin
      application.ProcessMessages;
      sleep(50);
      label1.Caption:=inttostr(strtoint(label1.Caption)+1);
      end;
    end;
      

  6.   

    application.ProcessMessages;
      sleep(50);