Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docked controls placed within TableLayout do not automatically size smaller than their creation size

This issue is better demonstrated than explained, so I've set up a git repo with Visual Studio 2010 project that be used to see the issue in action.

I have a project where I've added a ComboBox control (comboField) to a TableLayout control (tableLayoutPanel1). I've set the Dock property of the ComboBox to Fill so that it fills the cell of the TableLayout control that it has been placed in. I've also set the Dock property of the TableLayout control to Fill so that it fills the Form that it has been placed on. The width of the ComboBox is currently 193 pixels.

When I run the form and increase its width, the size of the ComboBox increases, as expected. When I reduce the size of the form, the ComboBox reduces in size until it reaches it's original size (193 pixels). At which point, the width of the ComboBox will not decrease any further, resulting in the right-hand side of the control being clipped. This is contrary to what I would expect: the width of the ComboBox will decrease to zero, given that no MinimumSize has been specified. Neither has a MinimumSize been specified for any of the other controls on the form, such as the TableLayout control.

In case it is relevant, the width of the first column of the TableLayout has is set to an Absolute size of 100 pixels, while the width of the second column of the TableLayout has been set to AutoSize.

Can anyone shed any light on why this form is behaving contrary to my expectations and advise on how I can get this working in the way I want? Any help would be much appreciated.

like image 608
Dan Stevens Avatar asked Jun 15 '12 11:06

Dan Stevens


1 Answers

I downloaded your code and did this change. it works now -

Do the 2nd column's SizeType to percent and make it 100%

Designer Code:-

this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));

enter image description here

like image 147
Angshuman Agarwal Avatar answered Oct 02 '22 13:10

Angshuman Agarwal