delphi - FireMonkey 并显示所有者表单的模式对话框中心

标签 delphi user-interface delphi-xe delphi-xe2 firemonkey

我在所有者表单中心显示模式对话框时遇到问题。我用于显示模式对话框的代码是:

procedure TfrmMain.btnOpenSettingsClick(Sender: TObject);
var
  sdSettingsDialog: TdlgSettings;

begin
   sdSettingsDialog := TdlgSettings.Create(Self);
   sdSettingsDialog.Position := TFormPosition.poOwnerFormCenter;

   try
      sdSettingsDialog.ShowModal;
   finally
     sdSettingsDialog.Free;
   end;
end;

也尝试更改设计器中的 Position 属性,但它似乎没有使对话框居中。

你能告诉我这里出了什么问题吗?

最佳答案

在 FireMonkey 中,ShowModal 未实现位置。 使用下面的类帮助器,您可以在调用 ShowModal 之前使用: sdSettingsDialog.UpdateFormPosition:

type
  TFormHelper = class helper for TForm
    procedure UpdateFormPosition;
  end;

procedure TFormHelper.UpdateFormPosition;
var
  RefForm: TCommonCustomForm;
begin
  RefForm := nil;

  case Position of
    // TFormPosition.poScreenCenter: implemented in FMX.Forms (only one)
    TFormPosition.poOwnerFormCenter:
      if Assigned(Owner) and (Owner is TCommonCustomForm) then
        RefForm := Owner as TCommonCustomForm;
    TFormPosition.poMainFormCenter:
      RefForm := Application.MainForm;
  end;

  if Assigned(RefForm) then
  begin
    SetBounds(
      System.Round((RefForm.Width - Width) / 2) + RefForm.Left,
      System.Round((RefForm.Height - Height) / 2) + RefForm.Top,
      Width, Height);
  end;
end;

关于delphi - FireMonkey 并显示所有者表单的模式对话框中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8195106/

相关文章:

delphi - 如何将字段接口(interface)注入(inject)到对象中

delphi - 接口(interface)委托(delegate)+重写

delphi - 如何在打开模态表单后立即将其关闭?

delphi - 如何将 TXT 文件作为资源添加到我的 EXE 文件中?

delphi - 无法在动态链接库 <dll> 中找到过程入口点 <function>

delphi - 处理具有不明确参数的重载函数

delphi - 应用程序 (TApplication) 实例在何时何地创建?

c++ - FLTK:窗口在 MacOS 上获得焦点时的事件

user-interface - 如何为我的最终用户提供运行时表单设计器?

java - 涉及 actionListener 的类不是抽象的