Described is a method and system by which a computer program window is
sized based on the content to display. The window may automatically
resize itself as content changes. When laying out an element tree of
elements that contain the content, the elements provide desired size
information to a parent container, and so on, up to the root element
(e.g., a window). If a window property is set to size to the content, a
window size is computed during layout, having a height and/or width based
on the child elements plus X and Y deltas for a window non-client area
and borders. Logic attached to window message handling controls changes
to the content/window, such as to automatically resize for changed
content, and to selectively turn off or persist the size to content
property. Sizing to content may be programmatically limited to one
dimension, with the other dimension fixed.