[FMX]一个简单的进度对话框

 

不说啥,看效果:

fmxprogress

调用代码:

ShowProgress('正在准备提交数据……',0);
Sleep(1000);
ShowProgress('正在提交第一阶段数据……',20);
Sleep(1000);
ShowProgress('正在提交第二阶段数据……',50);
Sleep(1000);
ShowProgress('正在确认提交结果……',75);
Sleep(1000);
ShowProgress('结果已确认,提交成功。',100);
Sleep(1000);
HideProgress;

源码:

unit progress;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls;

type
  TfrmProgress = class(TForm)
    Panel1: TPanel;
    lblHint: TLabel;
    Panel2: TPanel;
    pbProgress: TProgressBar;
    sbCancel: TSpeedButton;
    tmDelayShow: TTimer;
    procedure tmDelayShowTimer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmProgress: TfrmProgress;
procedure ShowProgress(AHint:String;AProgress:Integer);
procedure HideProgress;
implementation

{$R *.fmx}
procedure ShowProgress(AHint:String;AProgress:Integer);
begin
if not Assigned(frmProgress) then
  frmProgress:=TfrmProgress.Create(Application);
frmProgress.lblHint.Text:=AHint;
frmProgress.pbProgress.Value:=AProgress;
if not frmProgress.Visible then
  frmProgress.tmDelayShow.Enabled:=True;
frmProgress.Invalidate;
Application.ProcessMessages;
end;

procedure HideProgress;
begin
if Assigned(frmProgress) then
  frmProgress.Hide;
end;
procedure TfrmProgress.tmDelayShowTimer(Sender: TObject);
begin
tmDelayShow.Enabled:=False;
frmProgress.Show;
end;

end.

窗体定义:

object frmProgress: TfrmProgress
  Left = 0
  Top = 0
  BorderStyle = None
  ClientHeight = 480
  ClientWidth = 351
  Fill.Color = x80000000
  Fill.Kind = Solid
  Position = ScreenCenter
  Transparency = True
  Visible = True
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  DesignerMasterStyle = 3
  object Panel1: TPanel
    Align = Center
    Size.Width = 297.000000000000000000
    Size.Height = 141.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 0
    object lblHint: TLabel
      Align = Client
      Margins.Left = 5.000000000000000000
      Margins.Top = 5.000000000000000000
      Margins.Right = 5.000000000000000000
      Margins.Bottom = 5.000000000000000000
      Size.Width = 287.000000000000000000
      Size.Height = 46.000000000000000000
      Size.PlatformDefault = False
      TextSettings.VertAlign = Trailing
      Text = #27491#22312#25191#34892#25805#20316#65292#35831#31245#20505#8230#8230
    end
    object Panel2: TPanel
      Align = Bottom
      Padding.Top = 5.000000000000000000
      Position.Y = 56.000000000000000000
      Size.Width = 297.000000000000000000
      Size.Height = 85.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 1
      object pbProgress: TProgressBar
        Align = Top
        Orientation = Horizontal
        Margins.Left = 5.000000000000000000
        Margins.Right = 5.000000000000000000
        Position.X = 5.000000000000000000
        Position.Y = 5.000000000000000000
        Size.Width = 287.000000000000000000
        Size.Height = 10.000000000000000000
        Size.PlatformDefault = False
      end
      object sbCancel: TSpeedButton
        Align = Center
        ModalResult = 2
        Size.Width = 48.000000000000000000
        Size.Height = 48.000000000000000000
        Size.PlatformDefault = False
        StyleLookup = 'stoptoolbutton'
        Text = #21462#28040
      end
    end
  end
  object tmDelayShow: TTimer
    Enabled = False
    Interval = 500
    OnTimer = tmDelayShowTimer
    Left = 184
    Top = 88
  end
end

 

分享到: