Question Problem in resizing controls.

priyamtheone

Well-known member
Joined
Sep 20, 2007
Messages
96
Programming Experience
Beginner
Hi,
we all know how to dock or anchor controls so that they resize themselves accordingly when a form is resized. It works fine till we have rows of controls on left and right size of the form. But what if have three columns (Columns as in visual sense. I'm not talking about any column control containing other controls) of controls? For example a form having a bunch of controls in the left side, a bunch in the middle and a bunch in the right. There may be a few more bunches in the middle. Now while resizing the form, I want the controls to resize accordingly as well as change their positions to make space for the previous bunch of controls that are resizing.
I mean, while the user increases the form size horizontally, the controls of the second bunch should resize and at the same time they should move right because the controls of the first bunch are increasing horizontally too. When the user decreases the form size horizontally the same thing should occur in the reverse order.
I can manage it somehow using nested splitcontainers but that's too cumbersome. I would like to know if there's some better way to achieve it, like setting some property etc.?
Please help. Check the attached image. Please feel free to ask if my post isn't comprehensible. Regards.
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    24.6 KB · Views: 21
  • Untitled2.jpg
    Untitled2.jpg
    39 KB · Views: 20
I'm not talking about any column control containing other controls
In actual fact, yes you are. The TableLayoutPanel was created for just this sort of thing. You would add a TableLayoutPanel to your form with the appropriate number of rows and six columns. The three columns containing the Labels would be set to a fixed width and the other three would be set to a relative width such that they each occupy one third of the remaining space. The simplest option is to just set the three columns to 100% each and let the control sort it out. You can then use the Anchor property of each TextBox to anchor it inside its cell.
 
Check out the TableLayoutPanel control. Putting your label+textbox in a UserControl will make this a lot simpler. Anchor as mentioned, or Dock it.
 
Back
Top