Click here to Skip to main content
15,908,673 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I wanted to make a win forms app but the problem is when it is full sized.....The controls get all here and there.........and made some research and found out that it requires to write the margins in percentage but i could not find how to do it...........please help me......please tell me how to find the margins percentage..........Thanks in advance...........

Ahsan Naveed
[no name] 22-Aug-13 10:33am    
Perhaps you are confusing CSS with Winforms Anchor and Dock properties?
Ahsan98 22-Aug-13 10:35am    
No i dont think so I had a small chat with my cousin whose a programmer and he told me that i need to write margins in percentage.........although as it was a small chat i couldnt ask the why to do it.........
[no name] 22-Aug-13 10:44am    
I believe either you are confused or he is confused. Use the Anchor and Dock properties on your controls.
ridoy 22-Aug-13 10:54am    
some very weird things i hear from you,margins percentage need to just care about anchor and dock and that's all!

1 solution

Winforms does not work in percentages - it works in pixels and no control width or height can be expressed as a percentage of its container. I suspect your cousin is thinking of web design, where CSS allows you to specify these things in percentage terms.

You are either down to using the container Dock and Anchor properties or manually re-sizing controls in the Form.Resize event (a lot of work, and rarely produces a good result).

The alternative is to use WPF instead of WinForms, where the Grid ColumnDefinition.Width can be expressed in variable (and effectively percentage) terms by using a "*" in the definition. WPF has a very large learning curve however, which may make it unfeasible for you to use.
Share this answer

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