views:

255

answers:

1

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?

+6  A: 

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.

Bruce McGee
I figured I'd have to test every possible combination of properties -- I honestly didn't expect it to be that easy to find a non-OnResize case. But good to know the answer. Thanks!
Joe White