TForm.ManualDock 应该调用 onFormShow 吗?
当我输入这个问题时,我意识到它可能应该如此。
当调用 form.Create() 和调用 form.ManualDock(pagecontrol,pagecontrol.alClient) 时,将表单停靠到 TPageControl 会调用 FormShow。
取消停靠表单也会调用 show,我认为这是因为当您停靠/取消停靠时,表单实际上是“重置”的?
如果这是按照设计的,我将重构我不想在 onCreate 中触发的代码(除非这是糟糕的设计)。
As I typed this question I realize that it probably should.
Docking a form to a TPageControl calls FormShow when form.Create() is called and when form.ManualDock(pagecontrol,pagecontrol.alClient) is called.
Un-docking the form also calls show and I assume this is because the form is actually 'reset' when you dock/undock?
If this is as designed I'll just refactor the code I dont want to fire there to onCreate (unless that is bad design).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是否应该更多的是哲学问题而不是技术问题。
TForm.OnShow
事件由执行控制消息CM_DOCKCLIENT
也使用通过ManualDock
函数。在内部,此消息调用CM_SHOWINGCHANGED
触发事件本身。在下面的示例中,我将使用两个表单:Form1(带有页面控件和按钮)和 Form2(空且可停靠)。我认为两者都是自动创建的。
下面的代码证明了
OnShow
事件由CM_DOCKCLIENT
控件触发 信息。单击该按钮,将执行CM_DOCKCLIENT
消息和 Form2 的OnShow
事件被触发。Form1
和 Form2 的代码只有
OnShow
事件处理程序一个简单的解决方法是不要手动停靠 Form2(在
OnShow
事件),但由创建者停靠它,或者说通过显示它的表单。在前面的示例中,我在 Form1.OnShow 事件中显示了 Form2,因此我可以轻松地将其手动停靠在那里。If should or not is more philosophical than technical question. The
TForm.OnShow
event is fired by performing control messageCM_DOCKCLIENT
which is used also by theManualDock
function. Internally this message calls theCM_SHOWINGCHANGED
what fires the event itself.In the following example I will use two forms, Form1 (with a page control and a button) and Form2 (empty and dockable). I presume that both are auto created.
The following code is a proof that the
OnShow
event is fired by theCM_DOCKCLIENT
control message. Clicking on the button, theCM_DOCKCLIENT
message is performed and Form2'sOnShow
event is fired.Code for Form1
And Form2 has only the
OnShow
event handlerAn easy workaround is not to dock the Form2 manually by its own (in the
OnShow
event) but dock it by the creator or let's say by the form which displays it. In my previous example I've displayed the Form2 in the Form1.OnShow event, so I can easily dock it manually there.