【问题标题】:Delphi TTaskDialog position on openDelphi TTaskDialog 位置打开
【发布时间】:2020-12-06 11:30:14
【问题描述】:

通过 Delphi 10.2.3:TTaskDialog 始终在屏幕中心位置打开,并且由于它没有 Position 属性,因此似乎没有直接的方法来覆盖该行为。我希望我所有的 TTaskDialogs 都位于 poMainFormCenter。没有写一个 TTaskDialog 的替代品,有没有办法强制这种行为?

【问题讨论】:

    标签: delphi ttaskdialog


    【解决方案1】:

    您可能不知道Flags 属性和tfPositionRelativeToWindow 标志:

    如果设置,[the] 任务对话框相对于 [其] 父窗口居中。

    with TTaskDialog.Create(Self) do
      try
        Caption := Self.Caption;
        MainIcon := tdiNone;
        Title := 'Do you want to create a new batch of frogs?';
        CommonButtons := [tcbYes, tcbNo];
        Flags := [tfPositionRelativeToWindow];
        Execute;
      finally
        Free
      end;
    

    严格来说,这会将任务对话框相对于父窗体而不是主窗体定位,但我怀疑这是您真正想要的。

    tfPositionRelativeToWindow 标志映射到对TaskDialogIndirect 的底层 API 调用的 TDF_POSITION_RELATIVE_TO_WINDOW 标志:

    表示任务对话框相对于 hwndParent 指定的窗口定位(居中)。如果未提供标志(或未指定 hwndParent 成员),则任务对话框相对于监视器定位(居中)。

    【讨论】:

    • 优秀 - 这给了我我想要的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多