'请把下面的保存为 Form1.frmVERSION 5.00
Begin VB.Form frmHScrollBar
Caption = "给列表框加水平滚动条"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
Caption = "关闭"
Height = 495
Left = 3075
TabIndex = 2
Top = 810
Width = 1215
End
Begin VB.TextBox Text1
Height = 495
Left = 390
TabIndex = 1
Text = "Text1"
Top = 2505
Width = 3975
End
Begin VB.ListBox List1
Height = 2010
Left = 405
TabIndex = 0
Top = 255
Width = 1530
End
End
Attribute VB_Name = "frmHScrollBar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As LongConst LB_SETHORIZONTALEXTENT = &H194Private Sub Command1_Click()
Unload Me
End
End SubPrivate Sub form_load()
Me.ScaleMode = vbPixels
Me.Font.Size = List1.Font.Size
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
List1.AddItem Text1
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, 1.05 * Me.TextWidth(Text1), ByVal 0&
End If
End Sub
Begin VB.Form frmHScrollBar
Caption = "给列表框加水平滚动条"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
Caption = "关闭"
Height = 495
Left = 3075
TabIndex = 2
Top = 810
Width = 1215
End
Begin VB.TextBox Text1
Height = 495
Left = 390
TabIndex = 1
Text = "Text1"
Top = 2505
Width = 3975
End
Begin VB.ListBox List1
Height = 2010
Left = 405
TabIndex = 0
Top = 255
Width = 1530
End
End
Attribute VB_Name = "frmHScrollBar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As LongConst LB_SETHORIZONTALEXTENT = &H194Private Sub Command1_Click()
Unload Me
End
End SubPrivate Sub form_load()
Me.ScaleMode = vbPixels
Me.Font.Size = List1.Font.Size
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
List1.AddItem Text1
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, 1.05 * Me.TextWidth(Text1), ByVal 0&
End If
End Sub
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q192184
还可用listview
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 '在过程中用
SendMessage(List.hWnd,LB_SETHORIZONTALEXTENT,宽度,Byval 0&)
原来没有横向滚动条会自动加横向滚动条
不知道为什么?