What's the easiest way to write a please wait screen with Delphi?

前端 未结 6 563
感动是毒
感动是毒 2020-12-11 12:03

I just want a quick and dirty non-modal, non-closable screen that pops up and goes away to make 2 seconds seem more like... 1 second. Using 3-5 lines of code.

6条回答
  •  攒了一身酷
    2020-12-11 12:53

    I show a hint for a quick message, sth. like this:

    function ShowHintMsg(Form: TForm; Hint: string): THintWindow;
    var
      Rect: TRect;
    begin
      Result := THintWindow.Create(nil);
      Result.Canvas.Font.Size := Form.Font.Size * 2;
      Rect := Result.CalcHintRect(Form.Width, Hint, nil);
      OffsetRect(Rect, Form.Left + (Form.Width - Rect.Right) div 2,
                       Form.Top + (Form.Height - Rect.Bottom) div 2);
      Result.ActivateHint(Rect, Hint);
    
    // due to a bug/design in THintWindow.ActivateHint, might not be
    // necessary with some versions.
      Result.Repaint;
    end;
    
    procedure HideHintMsg(HintWindow: THintWindow);
    begin
      try
        HintWindow.ReleaseHandle;
      finally
        HintWindow.Free;
      end;
    end;
    
    procedure TForm1.Button3Click(Sender: TObject);
    var
      HintWindow: THintWindow;
    begin
      HintWindow := ShowHintMsg(Self, 'Please Wait...');
      try
    
        Sleep(2000);  // do processing.
    
      finally
        HideHintMsg(HintWindow);
      end;
    end;
    

提交回复
热议问题