Will a Delphi form always fire OnResize when it's shown?

萝らか妹 提交于 2019-12-14 01:27:58

问题


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.

(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.)

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?


回答1:


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.

It's easy to test. Just add some logging code to the main form's OnResize event, change the BorderStyle and run your app.



来源:https://stackoverflow.com/questions/1239407/will-a-delphi-form-always-fire-onresize-when-its-shown

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