在ListBox适当设定水平滚动条的宽度 作者:李志东 Option Explicit Private Const LB_SETHORIZONTALEXTENT = &H194 Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Sub Command1_Click() Dim max As Long, f As Font, i As IntegerMe.ScaleMode = vbPixels Set f = Me.Font Set Me.Font = List1.FontWith List1 For i = 0 To .ListCount If Me.TextWidth(.List(i)) > max Then max = Me.TextWidth(.List(i)) End If Next End With max = max + 10Set Me.Font = fSendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, max, ByVal 0& End SubPrivate Sub Form_Load() List1.AddItem "VB编程乐园" List1.AddItem "http://www.vbeden.com" List1.AddItem "这是一个特别特别长的选项,长到超过ListBox的范围" 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
Private Sub Form_Load() For i = 1 To 50 List1.AddItem "asdfasdfasdfasdasdfasdfasdfasdfasdfasfasdf" Next i End SubPrivate Sub List1_Click() List1.ToolTipText = List1.Text 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 Const LB_SETHORIZONTALEXTENT = &H194Private Sub Form_Load() SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, ByVal 300, ByVal 0 End Sub
作者:李志东
Option Explicit
Private Const LB_SETHORIZONTALEXTENT = &H194
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Sub Command1_Click()
Dim max As Long, f As Font, i As IntegerMe.ScaleMode = vbPixels
Set f = Me.Font
Set Me.Font = List1.FontWith List1
For i = 0 To .ListCount
If Me.TextWidth(.List(i)) > max Then
max = Me.TextWidth(.List(i))
End If
Next
End With
max = max + 10Set Me.Font = fSendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, max, ByVal 0&
End SubPrivate Sub Form_Load()
List1.AddItem "VB编程乐园"
List1.AddItem "http://www.vbeden.com"
List1.AddItem "这是一个特别特别长的选项,长到超过ListBox的范围"
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
For i = 1 To 50
List1.AddItem "asdfasdfasdfasdasdfasdfasdfasdfasdfasfasdf"
Next i
End SubPrivate Sub List1_Click()
List1.ToolTipText = List1.Text
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
Const LB_SETHORIZONTALEXTENT = &H194Private Sub Form_Load()
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, ByVal 300, ByVal 0
End Sub