How to create a delphi form containing multiple 'child' forms that can be moved/sized and show activated

此生再无相见时 提交于 2019-11-29 11:37:29

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.

You can get your desired behavior with parenting by the 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;


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);

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.

Call Windows.SetFocus(Form.Handle) which is somewhat more forceful than TForm.SetFocus. Specifically Windows.SetFocus will focus and activate a form that is inactive which I suspect is your main problem.

Having more than one form active feels wrong.

Finally, did you consider using MDI? It still works.

Cesar

I think MDI is the easiest way, in the main form set FormStyle=fsMDIForm, in the childs FormStyle=fsMDIChild.

That's it, this way you dont have to set the parent to make it work.

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