5

I've got a TCheckListBox on a form. Its Columns property is set to 2, and if there are more items than can fit on-screen in two columns, it puts a horizontal scrollbar across the bottom of the control.

Thing is, the way this form it laid out, it would be much more convenient to scroll vertically. But I can't seem to figure out how to make the box do that. I thought setting Columns to 1 should work, but it doesn't.

Anyone know how to make a TCheckListBox scroll vertically instead of horizontally?

4

1 回答 1

7

您需要设置Columns为 0。

对于所有正值,VCL 将LB_SETCOLUMNWIDTH消息发送到底层本机列表框控件,宽度参数设置为列表框客户端宽度除以列数。不适合的项目将以相同的列宽开始一个新列,因此水平滚动条变得可见。

如果Columns为 0,则有一个列跨越列表框的整个客户端宽度,不适合的项目将使垂直滚动条可见,并隐藏水平滚动条。

编辑:

当属性使用负值时会发生什么似乎真的很有趣Columns

该方法根据不为 0 的属性TCustomListBox.CreateParams()设置列表框样式。对于负值,设置样式标志,但 VCL 不发送消息,因此本机控件使用默认列宽。它被记录为:LBS_MULTICOLUMNColumnsLB_SETCOLUMNWIDTH

列表框使用的字体的平均字符宽度的 15 倍。

(搜索“LBS_MULTICOLUMN 样式指定”以找到相关的文本段落。)

于 2010-02-19T00:00:48.737 回答