如何使 TCheckListBox 垂直滚动?
我在表单上有一个 TCheckListBox。其 Columns 属性设置为 2,如果屏幕上两列无法容纳的项目数,则会在控件底部放置一个水平滚动条。
事实是,这种形式的布局方式,垂直滚动会更方便。但我似乎不知道如何让盒子做到这一点。我认为将 Columns 设置为 1 应该有效,但事实并非如此。
有人知道如何使 TCheckListBox 垂直滚动而不是水平滚动吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将
Columns
设置为0。对于所有正值,VCL会向底层本机列表框控件发送
LB_SETCOLUMNWIDTH
消息,并将宽度参数设置为列表框客户端宽度除以列数。不适合的项目将开始一个具有相同列宽的新列,因此水平滚动条变得可见。如果 Columns 为 0,则有一列跨越列表框的整个客户端宽度,不适合的项目将使垂直滚动条可见,并隐藏水平滚动条。
编辑:
人们似乎对将负值用于
Columns
属性时会发生什么感兴趣。TCustomListBox.CreateParams()
方法根据不同于 0 的Columns
属性设置LBS_MULTICOLUMN
列表框样式。对于负值,样式标志已设置,但 VCL 不发送 LB_SETCOLUMNWIDTH 消息,因此本机控件使用默认列宽。 记录为:(搜索“LBS_MULTICOLUMN 样式指定”以查找相关文本段落。)
You need to set
Columns
to 0.For all positive values the VCL sends a
LB_SETCOLUMNWIDTH
message to the underlying native list box control, with the width parameter set to the list box client width divided by the number of columns. Items that don't fit will start a new column with the same column width, so the horizontal scrollbar becomes visible.If
Columns
is 0 then there is a single column that spans the entire client width of the list box, and items that don't fit will make the vertical scrollbar visible, and hide the horizontal scrollbar.Edit:
There seems to be genuine interest what happens when a negative value is used for the
Columns
property.The method
TCustomListBox.CreateParams()
sets theLBS_MULTICOLUMN
list box style depending on theColumns
property being different from 0. For negative values the style flag is set, but the VCL doesn't send theLB_SETCOLUMNWIDTH
message, so the native control uses the default column width. It is documented to be:(Search for "The LBS_MULTICOLUMN style specifies" to find the relevant passage of text.)