给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 = &H194Private Sub Demo_LBox_GotFocus() Dim i As Integer Dim List_MaxL As Integer
' 获得选项内容的最大长度 For i = 0 To Demo_LBox.ListCount - 1 If Len(Demo_LBox.List(i)) > List_MaxL Then List_MaxL = Len(Demo_LBox.List(i)) End If Next i
' 判断是否内容显示不完全,如果是则添加水平滚动条 If Me.TextWidth("x") * List_MaxL > Demo_LBox.Width Then SendMessage Demo_LBox.hwnd, LB_SETHORIZONTALEXTENT, Me.TextWidth("x") * List_MaxL, ByVal 0& End If End SubPrivate Sub Form_Load() Dim i As Integer
' 为ListBox控件添加选项 For i = 0 To 10 Demo_LBox.AddItem ("This is long item " + CStr(i)) Next i
' 设置窗体坐标尺度模式和字体大小 Me.ScaleMode = vbPixels Me.FontSize = Demo_LBox.FontSize End Sub
Option Explicit
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 Command1_Click() List1.AddItem "Line 1" List1.AddItem "a big Line 2 some text some text" List1.AddItem "Line 3" addHorScrlBarListBox List1 End Sub
Public Sub addHorScrlBarListBox(ByVal refControlListBox As Object) ' 加横向滚动条
Dim nRet As Long Dim nNewWidth As Integer
nNewWidth = refControlListBox.Width + 100 ' 新宽度,以像素为单位。 nRet = SendMessage(refControlListBox.hwnd, _ LB_SETHORIZONTALEXTENT, nNewWidth, ByVal 0&) End Sub
ListView1.FlatScrollBar = False
ListView1.FullRowSelect = True
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 = &H194Private Sub Demo_LBox_GotFocus()
Dim i As Integer
Dim List_MaxL As Integer
' 获得选项内容的最大长度
For i = 0 To Demo_LBox.ListCount - 1
If Len(Demo_LBox.List(i)) > List_MaxL Then
List_MaxL = Len(Demo_LBox.List(i))
End If
Next i
' 判断是否内容显示不完全,如果是则添加水平滚动条
If Me.TextWidth("x") * List_MaxL > Demo_LBox.Width Then
SendMessage Demo_LBox.hwnd, LB_SETHORIZONTALEXTENT, Me.TextWidth("x") * List_MaxL, ByVal 0&
End If
End SubPrivate Sub Form_Load()
Dim i As Integer
' 为ListBox控件添加选项
For i = 0 To 10
Demo_LBox.AddItem ("This is long item " + CStr(i))
Next i
' 设置窗体坐标尺度模式和字体大小
Me.ScaleMode = vbPixels
Me.FontSize = Demo_LBox.FontSize
End Sub
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 Command1_Click()
List1.AddItem "Line 1"
List1.AddItem "a big Line 2 some text some text"
List1.AddItem "Line 3"
addHorScrlBarListBox List1
End Sub
Public Sub addHorScrlBarListBox(ByVal refControlListBox As Object)
' 加横向滚动条
Dim nRet As Long
Dim nNewWidth As Integer
nNewWidth = refControlListBox.Width + 100 ' 新宽度,以像素为单位。
nRet = SendMessage(refControlListBox.hwnd, _
LB_SETHORIZONTALEXTENT, nNewWidth, ByVal 0&)
End Sub