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 Long
VERSION 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 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 = &H194
Private Sub Command1_Click()
Unload Me
End
End Sub
Private 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