Delphi - 隐藏的MDI子表单创建 [英] Delphi - Hidden MDI child form creation

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

问题描述

我的应用程序有很多很多mdi表单,它们是在用户成功登录后创建的。我怎样才能最好地隐藏这个创作过程?它看起来很愚蠢,而且在创建新表单之后绘制mdi表单等等需要更长的时间。

My application has many many mdi forms and they are created after successfull user login. How can I best hide this creation process? It looks stupid and it takes longer time while mdi forms are painted after new form is created and so on.

到目前为止,我已经使用了LockWindowUpdate,它并不隐藏所有内容,但我想用启动画面显示创建进度,但我无法使用LockWindowUpdate。

So far I have used LockWindowUpdate, which doesn't hide everything, but I would like to use a splash screen showing the creation progress, but I can't with LockWindowUpdate.

最好的问候
Janne

Best Regards Janne

推荐答案

要创建不可见的MDI子窗体,可以将它们的 Visible 属性设置为 False ,另外你必须禁用VCL的强制行为 - 在创建时显示它们。这发生在 FormStyle 属性设置器 TCustomForm 中,它设置可见 True 为MDI子窗体。

To create MDI child forms invisible you set their Visible property to False, and in addition you have to disable the VCL behaviour of force-showing them during creation. This happens by the FormStyle property setter of TCustomForm, which sets Visible to True for MDI child forms.

如果设置 FormStyle 在对象检查器中,那么属性设置器将在表单创建时被调用,并且表单将不会立即显示,而只会在构造完成后才显示。这允许您通过覆盖 AfterConstruction()方法来重置显示表单的请求,如下所示:

If you set the FormStyle in the object inspector, then the property setter will be called during form creation already, and the form will not be shown immediately, but only after the construction is complete. This allows you to reset the request to show the form, by overriding the AfterConstruction() method like so:

procedure TMDIChild.AfterConstruction;
begin
  Exclude(FFormState, fsVisible);
  inherited;
end;

这将创建一个不可见的MDI子表单。

This will create an invisible MDI child form.

为了测试这个,你可以在IDE中创建一个新的MDI应用程序,重写子表单类中的方法,如上所示,并模拟一个长初始化:

To test this you can create a new MDI application in the IDE, override the method in the child form class like shown above, and simulate a long initialization:

procedure TMainForm.FileNew1Execute(Sender: TObject);
var
  i: integer;
begin
  for i := 1 to 10 do begin
    CreateMDIChild('NONAME' + IntToStr(MDIChildCount + 1));
    Update;
    Sleep(500);
  end;
  for i := 0 to MDIChildCount - 1 do
    MDIChildren[i].Visible := True;
end;

如果没有重写 AfterConstruction()方法将每半秒创建并显示一个MDI小孩。用重写的方法,它会在5秒的繁忙时间后显示出来,这会让你有机会显示你的启动画面。

Without the overridden AfterConstruction() method it will create and show a MDI child every half second. With the overridden method it will show them all after a busy period of 5 seconds, which will give you the chance to show your splash screen instead.

重要提示:

使用 LockWindowUpdate() 可以减少闪烁或抑制任何屏幕输出错误,错误,错误。 不要做,请阅读<一个href =http://blogs.msdn.com/oldnewthing/archive/2007/02/22/1742084.aspx =noreferrer>雷蒙德陈的文章关于这个话题来理解为什么这么说。

Using LockWindowUpdate() to reduce flicker or suppress any screen output is wrong, wrong, wrong. Don't do it, read the series of Raymond Chen articles on the topic to understand why that is so.

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

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