VB中Listbox控件添加水平垂直滚动条问题解决
(1) VB中Listbox控件若条目足够多,则自动会显示垂直滚动条
(2) 若仅仅需要水平滚动条,且每向右滚动一下移动一个条目,则将控件的columns 属性设为1
(3) 如果需要两种滚动条,则仅仅考虑水平滚动条即可,这时需要引入API函数,先判断是否超出条目范围,如果超出,则调用API生成水平滚动条,具体代码如下:
代码:
vb 为listbox添加水平滚动条
Private Declare Function SendMessage Lib "user32 " Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_SETHORIZONTALEXTENT = &H194
Private Sub setListWidth()
'如果列表框不够宽,则增加水平滚动条
html横向滚动条样式 Dim i As Integer
Dim List_MaxL As Integer
'获得选项内容的最大长度
For i = 0 To demo_lbox.ListCount - 1
''让list_maxl中保存最长的一条字串
If Len(demo_lbox.List(i)) > List_MaxL Then
List_MaxL = Len(demo_lbox.List(i)) + 2
End If
Next i
'判断是否内容显示不完全,如果是则添加水平滚动条
If Me.TextWidth("AA ") * List_MaxL > demo_lbox.Width Then
SendMessage demo_lbox.hwnd, LB_SETHORIZONTALEXTENT, Me.TextWidth("a") * List_MaxL, ByVal 0&
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
'为ListBox控件添加选项
For i = 0 To 100
demo_lbox.AddItem ("这是,最据jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj:(第 " + CStr(i)) & "行) "
'demo_lbox.AddItem ( "(第 " + CStr(i)) & "行) "
Next i
' 设置窗体坐标尺度模式和字体大小
Me.ScaleMode = vbPixels
Me.FontSize = demo_lbox.FontSize
'设置列表框的水平滚动条
Call setListWidth
End Sub
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论