在Edit的onkeydown事件中写一段代码,是一段耗时的代码,先在edit中输入几个字符,然后按回车,
在Edit的onkeydown事件中判断如果是回车键就执行这段耗时的代码,当代码执行时鼠标指针消失,
怎样才可以避免鼠标指针消失,请教各位大侠,谢谢

解决方案 »

  1.   

    鼠标怎么会消失的?是不是你的耗时的代码占用了太多的CPU时间,界面没有响应啊?如果是,就在耗时的代码中加上消息响应处理
      

  2.   

    是不是没用application.ProcessMessages ?unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Edit2: TEdit;
        procedure Edit1KeyDown(Sender: TObject; var Key: Word;
          Shift: TShiftState);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
      i:integer;
    begin
      if key=13 then
      begin
        for i:=1 to 100000 do
        begin
          edit2.Text :=  inttostr(i);
          application.ProcessMessages ;//试试不加这句的效果
        end;
      end;
    end;end.
      

  3.   

    procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
      msg: MSG;
    begin
      if Key=VK_RETURN then
    begin
      ShowMessage('enter');
      if PeekMessage(@msg,nil,nil,nil,PM_REMOVE) then
      begin
        TranslateMessage(@msg);
        DispatchMessage(@msg);
      end;
    end;
    end;
      

  4.   

    加上 if PeekMessage……语句就行了
      

  5.   

    这样时时,从新设置鼠标位置,等于就是刷新一下鼠标指针:
    GetCursorPos(APoint);//APoint:TPoint
    SetCursorPos(APoint.x,APoint.y);
      

  6.   

    application.ProcessMessages 就是这个
      

  7.   

    使用application.ProcessMessages即可;
    建议参见DELPHI消息处理