WinForms - How do you get the size of a control & ldquo; want & rdquo; be?

advertisements

When a Control is docked in a container (like a Panel) and is too wide to be shown (so a scroll bar appears), Control.Width seems to return the visible width of the Control (the top arrow in the picture).

How do you get the width that the Control "wants" to be? i.e. its full width that you'd see if you didn't have to scroll (the bottom arrow in the picture).

alt text http://img19.imageshack.us/img19/372/size.png


There are two different properties of controls that you might find useful for this purpose. There is the DefaultSize which is the Size of the control when it is initially created, and then there is the PreferredSize which is the size the control can fit into so to speak. All controls have these properties and PreferredSize should be the one you're looking for.