如何托管在另一个内部对齐的FireMonkey表单客户端? [英] How can I host a FireMonkey form client aligned inside another?

查看:39
本文介绍了如何托管在另一个内部对齐的FireMonkey表单客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Delphi XE7 FireMonkey项目正在增加控件,自然而然地,我开始使用框架.在VCL中使用框架的情况下,有些情况下我只是选择将一个(复杂的)VCL表单托管在另一个表单中,在表单的OnShow中创建并显示它,并将其设置为客户端对齐(这样做的好处)是您在编辑框架时悬挂的继承控件没有问题).

My Delphi XE7 FireMonkey project is growing controls and naturally I've moved to using frames. Where I've used frames in the VCL there have been situations where I've simply chosen to host one (complex) VCL form inside another instead, creating and displaying it in the form's OnShow and setting it client-aligned (the benefit of this is that you don't get issues with dangling inherited controls when you edit the frame).

不过,使用FireMonkey时,情况发生了些微变化,而我试图让子窗体客户端与另一个客户端对齐的尝试是绊脚石.我遇到了这个非常有用的SO链接显示了如何在VCL表单中托管FireMonkey表单,因此我使用以下代码在此基础上构建了该代码:

With FireMonkey though, things have changed slightly and my attempt to get a child form client aligned inside another is stumbling. I came across this very useful SO link which shows how to host a FireMonkey form inside a VCL form so I built on this with my code as follows:

procedure THostForm.FormCreate(Sender: TObject);
begin
  FForm := TChildForm.Create( Self );
  FForm.BorderIcons := [];
  FForm.BorderStyle := TFmxFormBorderStyle.None;
  FForm.Visible := True;
  FForm.Parent := Self;
  ResizeForm;
end;

procedure THostForm.FormResize(Sender: TObject);
begin
  inherited;
  ResizeForm;
end;

procedure THostForm.ResizeForm;
begin
  if Assigned(FForm) then
    FForm.SetBounds( Round(ClientRect.Left), Round(ClientRect.Top), Round(ClientWidth), Round(ClientHeight));
end;

这将生成一个子窗体,该子窗体随宿主窗体的大小而改变,但仍保留在屏幕的左上方.我也尝试过 ResizeForm 例程中的各种位置选项.在我看来,一种形式可能无法成为另一种形式的父形式,因为TForm不是IAligneableControl,而TFrame是.因此,我尝试将我的孩子表单停靠"到与宿主表单对齐的TRectangle客户端,其行为方式相同.

This produces a child form which changes size with the host form, but remains at the top left of the screen. I've tried various position options in the ResizeForm routine too. It seems to me that a form might not be able to be the parent of another because TForm is not IAligneableControl whereas TFrame is. So, I tried 'docking' my child form to a TRectangle client aligned in the host form and this behaves the same way.

有人检查过吗?

*以下MARCO建议的解决方案详细信息*

Marco的解决方案非常简洁,将托管"减少到仅两行代码.您要做需要确保您的孩子(托管)表单在另一个客户端对齐控件中具有所有内容-Marco建议使用TLayout,但是我已经有一个用于背景的TPanel,所以我没有完全修改子表单.因此,要将此子窗体 TChildForm 托管在 THostForm 内,只需执行以下操作:

Marco's solution is very neat and reduces the 'hosting' to just two lines of code. You do need to ensure that your child (hosted) form has everything inside another client aligned control - Marco suggested using a TLayout, but I already had a TPanel that I am using for a background so I had no modifications to the child form at all. So, to host this child form TChildForm inside a THostForm simply do:

procedure THostForm.FormCreate(Sender: TObject);
begin
  FForm := TChildForm.Create( Self );
  FForm.Panel1.Parent := Self;
end;

工作完成.谢谢马可.

推荐答案

在FireMonkey中混合表单和控件并不是一个好主意,因为它是VCL,因为在VCL中,控件和表单都是TWinControl的后代,并带有自己的Windows处理,而在FireMoneky中,表单与操作系统对象相关联,而控件与之不相关.

Mixing forms and controls in FireMonkey is not such a good idea as it is the VCL, because in the VCL controls and form are all TWinControl descendant with their own Windows handle, while in FireMoneky the form is associuated with an operating system object while the controls are not.

地址方案,我使用了不同的解决方案.使用客户端对齐,无用的TLayout创建了一个窗体,其中包含所有控件.在运行时,创建此表单并将Layout父级放置到新容器中(例如,多标签控件中的一个标签).

The address scenario, I've used a different solution. Created a form with a client-aligned, useless TLayout with all of the controls inside it. At runtime, create this form and parent the Layout to the new container (for example a tab in a multi tab control).

我已经使用过几次,从来没有发现任何大问题,这是一种动态创建标签页页面的好方法,以保持可视化开发模型.

I've used this a few times, never found big issues with it, and a nice way to dynamically crate tab pages keeping the visual development model.

这篇关于如何托管在另一个内部对齐的FireMonkey表单客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆