问题描述
我经常像这样将一个 TForm
后代嵌入到另一个 TForm
后代中:
I often embed a TForm
descendant into another TForm
descendant like this:
var
Form1: TForm1;
Form2: TForm2;
begin
Form2.Parent := Form1;
Form2.BorderStyle := bsNone;
Form2.Align := alClient;
Form2.Show;
end;
通常这可以正常工作,但有时 Form2 中的控件未正确对齐.此类问题有通用的解决方法吗?
Usually this works just fine, but sometimes the controls in Form2 are not aligned properly. Is there a general workaround for this sort of problem?
有人知道是什么导致了这种错位"?
Does anybody know what is causing this "misalignment"?
我知道我可以使用 TFrame
来完成这种工作,但是我有很多必须重写的库代码,而且我看不出为什么使用 TForm
应该不起作用吗?TForm
方法中的
I know that I could use TFrame
for this kind of job, but I have a lot of library code that I would have to rewrite and I do not see any reason why the TForm
in TForm
approach should not work?
我已经确定组件 TcxListView
是这里的罪魁祸首,我已向组件供应商 (DevExpress) 提交了错误报告:
I have identified the component TcxListView
as the culprit here, I have submitted a bug report to the component vendor (DevExpress):
http://www.devexpress.com/issue=B194161
Edit 2: DevExpress 的开发人员分析了这个问题,并说它实际上是 Embarcadero 的 TGridPanel
组件中的一个缺陷:
Edit 2: The developers at DevExpress have analyzed the problem and said that it is actually a defect in the TGridPanel
component by Embarcadero:
http://qc.embarcadero.com/wc/qcmain.aspx?d=90324
推荐答案
我也这样做,我使用以下例程来实现它:
I do this as well and I use the following routine to make it happen:
procedure TMyForm.PlaceInsideContainer(Container: TWinControl);
begin
Parent := Container;
Align := alClient;
BorderIcons := [];
BorderStyle := bsNone;
ParentBackground := True;
Show;
end;
我对此没有任何问题.我可以想象的唯一可能相关的区别是 BorderIcons 的分配,但我怀疑这会导致问题.
I have no problems with this. The only difference that I could possibly imagine could be relevant is the assignment of BorderIcons, but I would doubt that causes a problem.
这篇关于在另一个 TForm 中嵌入 TForm 时如何避免问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!