How to avoid issues when embedding a TForm in another TForm?

孤街醉人 提交于 2019-11-26 14:24:38

问题


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;

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"?

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?

Edit: 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: 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


回答1:


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;

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.




回答2:


I read a similar question (you'll have to google it) and the answer from TeamB was not to do this as the behaviour was unpredictable and that you should use TFrame instead (which is what I have always done).



来源:https://stackoverflow.com/questions/4385948/how-to-avoid-issues-when-embedding-a-tform-in-another-tform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!