tags:

views:

371

answers:

2

I am developing a quick app in C#. One thing that I want to do is the equivalent of Swing's (java) pack(). This is a call that allows me to say to a form (Frame in Java), resize yourself to the size of the sum of the components within yourself.

I have searched and searched (the components change dynamically so I cannot simply hardcode the form to the right size) but I cannot find the equivalent method in C#.

Does anyone know what it is called?

A: 

I assume you're using Windows Forms here. I do not believe it does. Forms always was a pain to use.

You should take a look at WPF.

Spencer Ruport
+1  A: 

You don't even need write code in order to 'pack' the form. In the forms designer, set the form's AutoSize property to true, and set the AutoSizeMode property to GrowAndShrink. And voila! At runtime (only), the form will dynamically resize itself to accommodate all the controls. If you want it to keep a little distance from the controls so that the controls won't 'stick' to the edges, you can set the Padding property (I'd recommend at least a value of 12,12,12,12).

Allon Guralnek