Skip to main content
 首页 » 编程设计

c#之ListBox控件下奇怪的空白

2024年02月05日10zhengyun_ustc

我需要添加适合整个表单的 ListBox 控件。所以我将 Dock 属性设置为 Fill。这是它在设计器中的样子:

这是它在运行时的样子:

ListBox 下的这个空白区域应该是做什么用的?我怎样才能删除它?

请您参考如下方法:

在属性窗口或代码中设置 IntegralHeigh = false

ListBox.IntegralHeight Property

Gets or sets a value indicating whether the control should resize to avoid showing partial items.

When this property is set to true, the control automatically resizes to ensure that an item is not partially displayed. If you want to maintain the original size of the ListBox based on the space requirements of your form, set this property to false.

By default, the ListBox and the CheckedListBox sizes are such that they show only whole items. If you want the ListBox or CheckedListBox to completely fill a docked area, set IntegralHeight to false. This causes the control to completely fill the area, but the last item is not fully displayed.

If the ListBox does not contain any items, this property has no effect.