Is there a way to determine the displayed height of a Windows Forms ListBox? In an application I am developing, I have a form with a ListBox docked in it. I need to automatically resize the form to remove the any extra space at the bottom which the ListBox does not use due to ListBox.IntegralHeight being set to true. Currently I am sizing the Form using Form.Height divided by ListBox.ItemHeight and then multiplying that value by ListBox.ItemHeight to round off the extra unnecessary height.
this.Height = (this.Height / this.listBox.ItemHeight) * this.listBox.ItemHeight;
This works great in Vista, but when I take my application to XP, something goes wrong and there still is extra space showing at the bottom of the form.
I can't use ListBox.PreferredHeight because that only gives me the amount of space the ListBox would take if all items were displayed.