首先应该建立锚点,就是当鼠标放在什么位置时可以修改ListBox 的大小。'下面是一个简单的例子,新建一个窗体,然后在窗体上放一个ListBox 和PictureBox '在PictureBox 上按住鼠标左键移动,可以改变ListBox 的大小Option ExplicitPrivate msngPreX As Single Private msngPreY As Single Private Sub Form_Load() Picture1.Top = List1.Top + List1.Height Picture1.Left = List1.Left + List1.Width End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then msngPreX = X msngPreY = Y End If End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then List1.Width = List1.Width + (X - msngPreX) List1.Height = List1.Height + (Y - msngPreY) Picture1.Top = List1.Top + List1.Height Picture1.Left = List1.Left + List1.Width End If End Sub
Private Sub Command2_Click() Dim i As Integer For i = 0 To 5 List1.AddItem "Item" & CStr(i) Next i List1.SetFocus List1.ListIndex = 5 End Sub
'--------------------------------------------------------------------------- '给 ListBox 加上水平滚动条 ' Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long Public Const LB_SETHORIZONTALEXTENT = &H194Private Sub Form_Load() SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, 700, ByVal 0& End Sub '---------------------------------------------------------------------------
'--------------------------------------------------------------------------- '给 ListBox 加上水平滚动条 ' Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long Private Const LB_SETHORIZONTALEXTENT = &H194Private Sub Form_Load() SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, 700, ByVal 0& End Sub '---------------------------------------------------------------------------
'在PictureBox 上按住鼠标左键移动,可以改变ListBox 的大小Option ExplicitPrivate msngPreX As Single
Private msngPreY As Single
Private Sub Form_Load()
Picture1.Top = List1.Top + List1.Height
Picture1.Left = List1.Left + List1.Width
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
msngPreX = X
msngPreY = Y
End If
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
List1.Width = List1.Width + (X - msngPreX)
List1.Height = List1.Height + (Y - msngPreY)
Picture1.Top = List1.Top + List1.Height
Picture1.Left = List1.Left + List1.Width
End If
End Sub
Dim i As Integer
For i = 0 To 5
List1.AddItem "Item" & CStr(i)
Next i
List1.SetFocus
List1.ListIndex = 5
End Sub
'给 ListBox 加上水平滚动条
'
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Public Const LB_SETHORIZONTALEXTENT = &H194Private Sub Form_Load()
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, 700, ByVal 0&
End Sub
'---------------------------------------------------------------------------
'给 ListBox 加上水平滚动条
'
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Private Const LB_SETHORIZONTALEXTENT = &H194Private Sub Form_Load()
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, 700, ByVal 0&
End Sub
'---------------------------------------------------------------------------