delphi - 如何使用Delphi标准确认对话框但带有复选框 "Don'不要再问我“?

标签 delphi dialog delphi-xe3 confirmation

在许多确认对话框中,拥有这样的选项(禁用确认的快速方法)很有用。 但我找不到如何做到这一点。我不想自己设计它,因为我需要这个对话框是标准的,并且不想在每次更新 Delphi 时重新设计。有没有简单的方法来使用带有此类复选框的 Delphi 标准确认对话框?

更新2。 Synopse 项目建议的 SynTaskDialog 库做得很好(我需要的一切,甚至更多),我将在我的项目中使用它。谢谢!

更新。所以,谢谢你们的想法。系统函数 MessageBoxCheck 是一个不错的解决方案,但似乎不太稳定。总的来说,我同意使用最新的 API 函数为用户提供现代操作系统的最佳 UI 体验并为旧系统使用老式设计是个好主意。目前我停留在简单的解决方案上(代码如下),但如果有人分享支持现代操作系统 UI 的代码,那就太好了。

function MsgDlgWithCB(const Msg,Title,CBMsg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn;
  var cbDontAskAnymore: TCheckBox): TForm;
var
  i: integer;
  b: TButton;
  y: integer;
begin
  Result := CreateMessageDialog(Msg, DlgType, Buttons, DefaultButton) ;
  Result.Position := poScreenCenter;
  cbDontAskAnymore := TCheckBox.Create(Result);
  cbDontAskAnymore.Caption := CBMsg;
  cbDontAskAnymore.Width := 130;
  y := -1;
  for i := 0 to result.ComponentCount-1 do
    if result.Components[i] is TButton then
    begin
      b := TButton(result.Components[i]);
      b.Left := b.Left + cbDontAskAnymore.Width + 16;
      Result.ClientWidth := Max(Result.ClientWidth, b.Left+b.Width+16);
      y := b.Top+b.Height-cbDontAskAnymore.Height;
    end;
  if y<0 then
    y := Result.ClientHeight - cbDontAskAnymore.height - 16;
  Result.Caption := Title;
  cbDontAskAnymore.Parent := Result;
  cbDontAskAnymore.Top := y;
  cbDontAskAnymore.Left := 8;
end;

function MessageDlgCheckbox(const Msg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn;
  var cbDontAskAnymore: Boolean;
  const Title: string ='Confirmation';
  const CBMsg: string = 'Don''t ask anymore'): integer;
var
  f: TForm;
  c: TCheckbox;
begin
  f := MsgDlgWithCB(Msg,Title,CBMsg,DlgType,Buttons,DefaultButton,c);
  try
    result := f.ShowModal;
    cbDontAskAnymore := c.Checked;
  finally
    f.free;
  end;
end;

最佳答案

您可以使用our Open Source SynTaskDialog unit .

自 Vista/7 起,Windows 提供了通用任务对话框。但以前版本的 Windows(即 Windows XP 或 2K)中没有可用的功能。

该单元(根据 MPL/GPL/LGPL 三重许可证获得许可)将在 Vista/7 下使用新的 TaskDialog API,并在 XP 或 2K 下使用纯 Delphi 代码和标准主题 VCL 组件对其进行模拟。它支持 Delphi 6 到 XE4,并且支持 Win32/Win64 Unicode。

这是在 Windows 7 64 位计算机下的结果:

enter image description here

这是从我们模拟的纯 Delphi 代码创建的相同对话框:

enter image description here

由于此屏幕截图是在 Win 7 计算机上制作的,因此样式是该操作系统的 native 样式。当对话框的模拟版本在 XP 上运行时,它会以该操作系统 native 的样式显示。

您有“下次不再询问此设置”复选框...并且可能还有更多!

关于delphi - 如何使用Delphi标准确认对话框但带有复选框 "Don'不要再问我“?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18378956/

相关文章:

Android:对话框在 droid 3 上有额外的、丑陋的空间?

java - 当用户选择 "Cancel"时保持 Java 应用程序打开?

delphi - 修复 Delphi XE3 中的 VCL 样式目录

mysql - DBX 错误 : Driver could not be properly initialised

string - 查找字符串中最后一次出现的 char

.net - 有没有办法创建 .net 用户控件以便在 delphi 表单上使用它们?

excel - 导出 Excel 内部服务

listview - 对话框中的 ListView ,适合文本

delphi - IPPeerCommon 和 IPPeerClient

delphi - Delphi 的 tee 图表未在 3d 中显示条形图