Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my program I create dynamic buttons. How can I automatic resize the form that I can see all the buttons on the from?
Posted
Updated 23-Nov-10 7:53am
Comments
Henry Minute 23-Nov-10 14:14pm    
Following your comment. There is not a reliable method that I am aware of. The Form Class does have an AutoSizeMode property that you might like to experiment with, although I have never managed to use it successfully.

Set the Width and Height properties.
 
Share this answer
 
You need to keep track of 4 values.

The lowest Y value used by any of your controls. (Top)
The highest Y value used by any of your controls. (Bottom)
The lowest X value used by any of your controls. (Left)
The highest X value used by any of your controls. (Right)

Then a simple sum will give you the required width. Add whatever figure you want to have as a border (remember to multiply that by two for a border at each end). Then set the ClientSize of your Form to those values.
 
Share this answer
 
Comments
Sandeep Mewara 23-Nov-10 14:10pm    
Comment from OP:
But can i do this automatically so i don't have to set a Widht an Height?
Use Form1.AutoSize = true; The default is always false and it won't work in the designer, only at run time. It works fine for the cases I tried, but it does funky stuff if you anchor all your controls, etc.
 
Share this answer
 
Comments
dejf111 2-Oct-20 5:05am    
It doesn't work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900