C# – ListBox AutoSizes by item height

cdocklistboxtablelayoutpanelwinforms

I use TableLayoutPanel for all my elements in a form. I use Dock Fill to autosize a TextBox and a ListBox. TextBox fits perfectly in a cell of the TableLayoutPanel but not a ListBox. It autosizes by item height.

enter image description here

How to delete this gap between the bottom of the ListBox and the bottom of the form? I know I can set the height of the ListBox by a certain value (e.g. item height in the ListBox is 16, 16 * 10 elements= 160, 160 will fit correctly), but is there any other solutions?
I'm using C#.

Best Answer

Set the ListBox's property IntegralHeight = false; so that it won't resize the control by the item height variable.

Related Topic