FMXUI - UI.Dialog 示例(比較漂亮)


在 FMXUI 開源庫,增加了 UI.Dialog 單元。此單元實現了跨平台的基礎對話框組件。使用時引用 UI.Dialog 即可。如果需要自定義對話框的樣式, 可以添加一個 TDialogStyleManager 組件在主窗體中。

GIT:  https://github.com/yangyxd/FMXUI

 

對話框效果演示圖(默認樣式,Windows平台):

 

此 Demo 已經包含在源碼庫中,主要代碼如下:

復制代碼
uses
  UI.Dialog, UI.Async;

{ TFrmaeDialog }

procedure TFrmaeDialog.ButtonView1Click(Sender: TObject);
begin
  TDialogBuilder.Create(Self)
    .SetMessage('我是一個消息框。')
    .Show;
end;

procedure TFrmaeDialog.ButtonView2Click(Sender: TObject);
begin
  TDialogBuilder.Create(Self)
    .SetMessage('我是一個消息框。這里顯示消息內容')
    .SetNegativeButton('Negative',
      procedure (Dialog: IDialog; Which: Integer) begin
        Hint(Dialog.Builder.NegativeButtonText);
      end
    )
    .SetNeutralButton('Neutral',
      procedure (Dialog: IDialog; Which: Integer) begin
        Hint(Dialog.Builder.NeutralButtonText);
      end
    )
    .SetPositiveButton('Positive',
      procedure (Dialog: IDialog; Which: Integer) begin
        Hint(Dialog.Builder.PositiveButtonText);
      end
    )
    .Show;
end;

procedure TFrmaeDialog.ButtonView3Click(Sender: TObject);
begin
  TDialogBuilder.Create(Self)
    .SetTitle('我是標題文本')
    .SetMessage('我是一個消息框。這里顯示消息內容')
    .SetNegativeButton('Negative',
      procedure (Dialog: IDialog; Which: Integer) begin
        Hint(Dialog.Builder.NegativeButtonText);
      end
    )
    .SetPositiveButton('Positive',
      procedure (Dialog: IDialog; Which: Integer) begin
        Hint(Dialog.Builder.PositiveButtonText);
      end
    )
    .Show;
end;

procedure TFrmaeDialog.ButtonView4Click(Sender: TObject);
begin
  TDialogBuilder.Create(Self)
    .SetTitle('我是標題文本')
    .SetItems(['列表項 - 1', '列表項 - 2', '列表項 - 3', '列表項 - 4', '列表項 - 5'],
      procedure (Dialog: IDialog; Which: Integer) begin
        Hint(Dialog.Builder.ItemArray[Which]);
      end
    )
    .Show;
end;

procedure TFrmaeDialog.ButtonView5Click(Sender: TObject);
begin
  TDialogBuilder.Create(Self)
    .SetTitle('我是標題文本')
    .SetSingleChoiceItems(['列表項 - 1', '列表項 - 2', '列表項 - 3', '列表項 - 4', '列表項 - 5'], 1)
    .SetPositiveButton('取消')
    .SetNegativeButton('確定',
      procedure (Dialog: IDialog; Which: Integer) begin
        Hint('選擇了: ' + Dialog.Builder.ItemArray[Dialog.Builder.CheckedItem]);
      end
    )
    .Show;
end;

procedure TFrmaeDialog.ButtonView6Click(Sender: TObject);
begin
  TDialogBuilder.Create(Self)
    .SetTitle('我是標題文本')
    .SetMultiChoiceItems(['列表項 - 1', '列表項 - 2', '列表項 - 3', '列表項 - 4', '列表項 - 5'], [])
    .SetPositiveButton('取消')
    .SetNegativeButton('確定',
      procedure (Dialog: IDialog; Which: Integer) begin
        Hint(Format('選擇了 %d 項.', [Dialog.Builder.CheckedCount]));
      end
    )
    .Show;
end;

procedure TFrmaeDialog.ButtonView7Click(Sender: TObject);
begin
  ShowWaitDialog('正在執行任務...', False);
  TAsync.Create()
  .SetExecute(
    procedure (Async: TAsync) begin
      Sleep(3000);
    end
  )
  .SetExecuteComplete(
    procedure (Async: TAsync) begin
      HideWaitDialog;
    end
  ).Start;
end;

procedure TFrmaeDialog.ButtonView8Click(Sender: TObject);
begin
  ShowWaitDialog('正在執行任務...',
    procedure (Dialog: IDialog) begin
      Hint('任務被取消');
    end
  );
  TAsync.Create()
  .SetExecute(
    procedure (Async: TAsync) begin
      Sleep(5000);
    end
  )
  .SetExecuteComplete(
    procedure (Async: TAsync) begin
      if not IsWaitDismiss then // 如果任務沒有被中斷
        Hint('任務執行完成.');
      HideWaitDialog;
    end
  ).Start;
end;

procedure TFrmaeDialog.DoShow;
begin
  inherited;
  tvTitle.Text := Title;
end;

procedure TFrmaeDialog.SpeedButton1Click(Sender: TObject);
begin
  Finish;
end;
復制代碼

 

http://www.cnblogs.com/yangyxd/articles/5877638.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM