📄 waitun.pas
字号:
unit WaitUn;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls,
ComCtrls,math;
type TWaitCursor=class(TObject)
private
OldCursor:TCursor;
public
constructor Create;
destructor Destroy; override;
end;
type
TRepMyWait= class(TComponent)
private
thWaitForm :tForm;
// OutStepNN,OutNNCount:integer;
WaitC:TWaitCursor;
function GetProgressbarPosition:integer;
procedure SetProgressBarPosition(Value:integer);
function GetProgress:TProgressBar;
public
constructor Create(MSG:String;X:integer=-1;Y:integer=-1); reintroduce; overload;
destructor DESTROY ; override;
procedure DopText(Text:String);
// procedure SetStep(Step:integer);
procedure SetPos(Top,Left:integer);
procedure ShowProgress;
procedure HideProgress;
property ProgressBarPos:integer read GetProgressbarPosition write SetProgressBarPosition;
property ProgressBar:TProgressBar read GetProgress;
procedure HIDE;
procedure SHOW;
end;
implementation
uses WaitUnF;
constructor TRepMyWait.Create(MSG:string;X:integer=-1;Y:integer=-1);
var i:integer;
thTop,MaxTop:integer;
thLeft:integer;
begin
WaITC:=TWaitCursor.Create;
// OutStepNN:=1;
thWaitForm:=twaitform.Create(Application);
(ThWaitForm as TWaitForm).RXLabel1.Caption:=MSG;
// Randomize;
// thWaitForm.position:=poDesigned;
if (X<>-1) or (Y<>-1) then begin
thWaitForm.Position:=poDesigned;
thWaitForm.Top:=X;
thWaitForm.Left:=y;
end
else begin
thTop:=thWaitForm.Top;
MaxTop:=Screen.Height-thWaitForm.Height;
thLeft:=(Screen.width - thWaitForm.width) div 2;
// thWaitForm.AnimatedImage.GlyphNum:=random(thWaitForm.AnimatedImage.NumGlyphs);
for i:=0 to Screen.FormCount-1 do
if not (Screen.Forms[i]=thWaitForm) and ((Screen.Forms[i] is TWaitForm))
// and (Screen.Forms[i].Position<>poDesigned)
then begin
thTop:=Max(Screen.Forms[i].Top+Screen.Forms[i].Height,thTop);
if thTop>=MaxTop then begin
// thTop:=MaxTop;
exit;
end;
end;
if thTop<>thWaitForm.Top then begin
thWaitForm.position:=poDesigned;
thWaitForm.Top:=thTop;
thWaitForm.Left:=thLeft;
end;
thWaitForm.Update;
end;
thWaitForm.Show;
thWaitForm.Update;
// Priority:=tpTimeCritical;
Inherited Create(Application);
end;
{
procedure TMyWait.SetStep(Step:integer);
begin
OutStepNN:=Step;
OutNNCount:=1;
end;
}
procedure TRepMyWait.SetPos(Top,Left:integer);
begin
ThWaitForm.Hide;
ThWaitForm.Top:=Top;
ThWaitForm.Left:=Left;
ThWaitForm.Show;;
end;
procedure TRepMyWait.DopText(Text:string);
begin
(thWaitForm as twaitform).Caption:=Text;
thWaitForm.Update
end;
destructor TRepMyWait.DESTROY;
begin
// Suspend;
// Terminate;
// WaitFor;
if ThWaitForm.visible then thWaitForm.Close;
thWaitForm.Free;
WaitC.Free;
Application.Processmessages;
inherited Destroy;
end;
function TRepMyWait.GetProgressbarPosition:integer;
begin
if assigned(ThWaitForm) then begin
Result:=(thWaitForm as twaitform).ProgressBar.Position
end
else Result:=0;
end;
procedure trepMyWait.SetProgressBarPosition(Value:integer);
begin
if assigned(ThWaitForm) then begin
(thWaitForm as twaitform).ProgressBar.Position:=Value;
thWaitForm.update
end
end;
procedure trepMyWait.ShowProgress;
begin
if Assigned(THWaitForm) then begin
(thWaitForm as twaitform).ShowProgress
end;
end;
procedure trepMyWait.HideProgress;
begin
if Assigned(THWaitForm) then begin
(thWaitForm as twaitform).HideProgress;
thwaitForm.update;
end;
end;
function trepMyWait.GetProgress:TProgressBar;
begin
if Assigned(THWaitForm) then begin
Result:=(thWaitForm as twaitform).ProgressBar;
end
else Result:=nil;
end;
procedure trepMyWait.HIDE;
begin
thWaitForm.Hide;
end;
procedure trepMyWait.SHOW;
begin
ThWaitForm.Show;
ThWaitForm.Update;
end;
constructor TWaitCursor.Create;
begin
OldCursor:=Screen.Cursor;
Screen.Cursor:=crHourGlass;
end;
destructor TWaitCursor.Destroy;
begin
inherited;
Screen.Cursor:=OldCursor;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -