Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a Windows form application. I set the dock Porperty of the child control to Fill, Now the control will resize automatically when I resize main dialog. But I want to resize my chld control to a fixed ratio. How I can do this in windows form application?

(Eg: 40 by 40 to 30 by 30, 20 by 20,50 by 50 etc when I resize my Docked Windows Form application)
Posted
Comments
dan!sh 25-Jan-16 5:40am    
So you want your form to be a square all the time?
Arun Kumar K S 25-Jan-16 5:44am    
Not Form dialog. I want my child panel control square all the time and need to grow and shrink when I resize Form

Setting Dock to fill would mean that the child control will fill the parent completely. Now in your case, you are looking for a square panel. To achieve this, in the Form's resize event handler, ensure that you are making the panel a square. Something like this:

C#
void Form1_Resize(object sender, EventArgs e)
       {
           panel1.Height = panel1.Width;
       }


You might want to put in some logic as to which side should be retained, height or width. Note that this may result in some flickering.
 
Share this answer
 
You can't do that automatically - the Anchor and Dock properties are both designed to flex the size of controls independently on the vertical and horizontal, and don't have an option for maintaining an aspect ratio.

You can do it - but you will have to handle the form Resize event and set the appropriate Width and Height of your control yourself.
 
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