问题描述
我创建了一个包含一个或多个子表单的表单。在我的编辑模式下,每个子窗体都显示其边框和标题栏,允许其移动和调整大小(有点像旧的MDI应用程序)。在我的编辑模式下,边框消失,子窗体固定在适当的位置。对于我的简单演示,我将这样创建子表单:
I've created a form that hosts one or more 'child' forms. In my edit mode, each child form shows its border and caption bar allowing it to be moved and sized (a bit like the old MDI app). Out of my edit mode, the borders disappear and the child forms are fixed in position. For my simple demo, I'm creating the child forms thus:
procedure TForm1.Button1Click(Sender: TObject);
var
Frm : TForm;
begin
Frm := TForm3.Create( Self );
Frm.Parent := Self;
Frm.Visible := True;
结果是这样的布局:
The result is a layout like this:
我注意到子窗体中的编辑控件从未处于活动状态。我希望点击表单显示有效的标题栏颜色,就像活动的应用程序在单击时四处移动一样。我认为子窗体的尸体行为是因为它们处于非活动状态,但是尝试执行ChildForm.SetFocus之类的操作无效。
I notice that the edit controls in the child forms are never active. I would like to have the 'clicked' form show an active caption bar colour just like active apps move around when clicked. I presume my 'corpse' behaviour of the child forms is because they are inactive but attempts to do things like ChildForm.SetFocus do nothing.
我需要做什么启用这些编辑控件并显示其中一种形式为选定?
What do I need to do to get these edit controls alive and to show one of the forms as 'selected' please?
(如果可能的话,我也很想选择一种以上形式) )
(I'd really like to 'select' more than one form too if possible)
推荐答案
导致此行为的是VCL的育儿机制。我不知道确切的原因,我想这会花一些时间,因为它是一种复杂的机制。
What's causing the behavior is the VCL's parenting mechanism. I don't know the exact reason, would take some time to figure it out I guess since it's somewhat a complicated mechanism.
api:
procedure TForm1.Button1Click(Sender: TObject);
var
Frm : TForm;
begin
Frm := TForm3.Create( Self );
// Frm.Parent := Self;
windows.SetParent(Frm.Handle, Handle);
Frm.Visible := True;
您肯定会失去与VCL的某些同步,例如与父相关的属性,锚定,所有权等。关于api甚至可能会出现问题,例如缺少WS_CHILD标志...试试看,看看它是否满足您的需求。.
You'll lose some synchronization with the VCL for sure, like parent dependent properties, anchoring, ownership etc.. It might even be problematic with respect to the api, like the missing WS_CHILD flag... Try it and see if it works to your needs..
要想拥有一种以上的有效形式,可以告诉其中任何一种进行相应绘制:
To have a feel of more than one active form, you can tell any of them to paint accordingly:
SendMessage(Frm.Handle, WM_NCACTIVATE, WPARAM(True), 0);
当任何表单收到此消息时,它将重新绘制其非客户区域以反映其(据说)已激活状态。为wParam传递 false将导致相反的结果。
When any form receives this message it will redraw its non-client area to reflect its (supposedly) activated status. Passing 'false' for wParam will cause the opposite.
这篇关于如何创建包含多个可以移动/调整大小并显示为已激活的“子”表单的delphi表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!