问题描述
如果我创建一个新的Delphi表单,钩住它的OnResize事件,然后运行该应用程序,则会在显示窗口之前触发OnResize。我不知道对于任何窗口,这种情况是否会一直发生。
If I create a new Delphi form, hook its OnResize event, and run the app, OnResize is fired before the window is shown. What I don't know is whether this will always happen, for any window.
(对于熟悉Windows API的任何人,我都将其追溯到ShowWindow调用在TCustomForm.ShowingChanged(Delphi 2007中的Forms.pas第5503行)中,至少对于未设置其他属性的新窗口,它显然触发了 WM_SIZE
...。尚未看到ShowWindow总是触发 WM_SIZE
的记录,所以我不知道我是否可以依靠它。)
(For anyone familiar with the Windows API, I've traced it to the ShowWindow call in TCustomForm.ShowingChanged (Forms.pas line 5503 in Delphi 2007), which apparently triggers a WM_SIZE
... at least, for a new window with no other properties set. I haven't seen it documented that ShowWindow always fires WM_SIZE
, so I don't know whether I can count on this or not.)
因此:在首次显示OnResize时,我是否可以依靠TForm 始终触发它?还是有这种情况(例如,如果窗口不可调整大小,也许,如果Position属性具有某些值,等等。)在第一次显示该窗口之前可能不会触发OnResize吗?
So: Can I rely on a TForm always firing OnResize when it's first shown? Or are there circumstances (maybe if the window is non-resizable, maybe if the Position property has certain values, etc.) where OnResize might not fire before the window is first shown?
推荐答案
否,取决于BorderStyle之类的内容,此事件并不总是在表单显示时触发。例如,对于bsSingle,它会在启动时触发,而对于bsDialog,则不会。
No, this event doesn't always fire when the form shows, depending on things like BorderStyle. For example, it fires on startup for bsSingle, but not for bsDialog.
易于测试。只需在主窗体的OnResize事件中添加一些日志记录代码,更改BorderStyle并运行您的应用即可。
It's easy to test. Just add some logging code to the main form's OnResize event, change the BorderStyle and run your app.
这篇关于显示时,Delphi表单会始终触发OnResize吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!