Delphi-表单中的表单 [英] Delphi - form within form

查看:104
本文介绍了Delphi-表单中的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于审美的原因,我想在另一个表单之上显示一个表单,就像它是一个组件一样,例如TPanel。它应该与父对象一起调整大小,随着父标题栏的拖动而移动。等等。

  --------- -------------------- 
|主表单组件1 |
-----------------------------
|主| 嵌入式 |
|形式表格在这里|
| comp 2 | |
-----------------------------

我能这样做吗?




我现在倾向于MDI ...

解决方案

在设计时将一个面板放置在您想要嵌入表单的位置。在运行时,创建表单,然后将嵌入表单的Parent属性设置为面板。

 过程TParentForm.FormCreate(ASender: TObject); 
开始
FEmbeddedForm:= TEmbeddedForm.Create(self);

FEmbeddedForm.Parent:= Panel1;
FEmbeddedForm.Align:= alClient;
FEmbeddedForm.Visible:= True;

结尾;

编辑:



如果要停止显示窗口标题和边框,请将其添加到 FormCreate()

的底部

  LForm.Caption:=''; 
LForm.BorderStyle:= bsNone;

顺便说一句,我不是在框架上使用父母形式,而是在回答问题。框架很棒(我一直都在用它们),但是它们与表单完全不一样。它们几乎完全像一个带有控件的面板。



例如,一个框架既没有OnCreate事件,也没有OnShow事件,当您重用它们并需要这种行为时,这有时会很痛苦。 / p>

N @


For aesthetic reasons, I want to show a form on top of another form, just as if it were a component, say like a TPanel. It should resize with the parent, move around as the parent is dragged by its title bar, etc.

-----------------------------
| main form component 1     |
-----------------------------
| main |  the 'embedded'    |  
| form |  form goes here    |
|comp 2|                    |
-----------------------------

can I do that? If so how?


I am now leaning towards MDI...

解决方案

Put a panel where you want your embedded form to be at design time. At run time, Create the form, then set the embedded form's Parent property to the panel.

procedure TParentForm.FormCreate(ASender: TObject);
begin
  FEmbeddedForm := TEmbeddedForm.Create(self);

  FEmbeddedForm.Parent := Panel1;
  FEmbeddedForm.Align := alClient;
  FEmbeddedForm.Visible := True;

end;

Edit:

If you want to stop the window title and border from being displayed, add this to the bottom of the FormCreate()

  LForm.Caption := '';
  LForm.BorderStyle := bsNone;

BTW, I am not advocating using parented forms over frames, just answering the question. Frames are great (I use them all the time), but they are not exactly the same as Forms. They are almost exactly like a panel with controls on it.

For instance, a frame does not have an OnCreate event, nor an OnShow event, which can be painful sometimes when you are reusing them and need that sort of behavior.

N@

这篇关于Delphi-表单中的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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