gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:52:49 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com