【问题标题】:Firemonkey - How to position a new form under a TComponentFiremonkey - 如何在 TComponent 下放置新表单
【发布时间】:2018-12-07 16:14:22
【问题描述】:

我正在使用 Delphi 10 和 Firemonkey 为 Windows/Apple 开发应用程序。 我的主窗体有一个 TButton。 当我按下 TButton 时,我想在 TButton 下创建并定位 Form1。 这是我的代码:

//Transposes the coordinates in the context of the form. 
myTPointF := TButton.LocalToAbsolute(TButton.Position.Point);

//Transposes the coordinates in the context of the screen. 
myTPointF := ClientToScreen(myTPointF);

Form1.Top := FloatToStr(myTPointF.X) + Round(TButton.Height);
Form1.Left := FloatToStr(myTPointF.Y);

如果 TButton 靠近表单(不是屏幕)的 Point(0,0),它可以工作,但离该点越远,当我打开它时,Form1 错误就越多。

图片链接: https://ibb.co/85dfr9R https://ibb.co/t2stMHv

提前感谢您的帮助。

【问题讨论】:

  • 您的意思是 所有 Apple 产品吗?还是只有一种特定的操作系统,例如 MacOS?在 iOS 中你肯定不想要这样的东西,对吧?
  • @DavidS 欢迎来到 Stackowerflow。该社区的成员通过 SO 引擎将图像存储在他们的帖子中。避免使用外部链接,因为它们可能会变得无法访问并且 Q 将变得无用。

标签: delphi firemonkey


【解决方案1】:

您不应仅使用LocalToAbsolute() ClientToScreen(Button1.Position.Point)。您还可以在您提供的代码中交换 XY

最好先设置第二个表单可见,因为除了主表单之外的其他表单不一定要在它们第一次在Fmx 框架中显示之前创建。

这行得通:

procedure TForm14.Button1Click(Sender: TObject);
var
  newpos: TPointF;
begin
  Form15.Visible := True;

  newpos := ClientToScreen(Button1.Position.Point);
  Form15.Left := Round(newpos.X);
  Form15.Top  := Round(newpos.Y+Button1.Height);
end;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 2012-02-21
    • 1970-01-01
    • 2014-03-27
    • 2012-09-27
    相关资源
    最近更新 更多