Suppose every once in a while in your application you need to have a popup dialog being shown. This dialog is a value picker, nothing more. It shows as many values as your screen can handle.
Problem happens when list population takes considerable amount of time, say, 5 seconds.
Until then you are completely unsure which size it needs to resize to.
Attached is a piece of production quality code, with irrelevant features and optimizations left out.
In this implementation, after list finished loading, the popup dialog is being resized to 75% of the owner form (you can tweak this value for your needs).
If a user keeps moving the form around while the list is loading, the resize-to-fit action is postponed until the user feels tired of playing with windows.