views:

854

answers:

1

(WinForms .net 2.0)

I'm making a form which, much like the standard MessageBox, has a single label on it and should grow horizontally and vertically if the text on the label grows. Horizontal seems easy enough, by setting AutoSize = true on the label and the form. However, I also want to make the label grow vertically, ie if it has newlines, but this doesn't seem so straightforward. I'm sure it is, but what settings are needed so that the label and form will grow vertically? I've got my label set to Anchor = top, left, right, bottom, so I'd have thought that when text with newlines is set in the label the height of the label will increase, and since Anchor = top & bottom it will force the form to increase in height. This doesn't seem to happen. What am I missing?

+1  A: 

set Autosize=True and AutoSizeMode=GrowAndShrink on the form. Also make sure your controls will auto size to their content. Also don't anchor to all four sides.

Joe
why not anchor to all four sides?
Rory
in the test I did, anchoring to all four sides prevented the form from resizing correctly. I can send you the example if you would like.
Joe