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 WM_VSCROLL = &H115
Private Const WM_HSCROLL = &H114
Private Sub Command1_Click()
'SendMessage TreeView1.hwnd, WM_VSCROLL, 0, vbNull '上
'SendMessage TreeView1.hwnd, WM_VSCROLL, 1, vbNull '下
'SendMessage TreeView1.hwnd, WM_HSCROLL, 0, vbNull '左
SendMessage TreeView1.hwnd, WM_HSCROLL, 1, vbNull '右
End Sub
Private Sub Form_Load()
Dim i As Integer
TreeView1.Style = tvwTreelinesPlusMinusPictureText
For i = 1 To 50
TreeView1.Nodes.Add , , GetNextKey, "Node " & i
Next i
TreeView1.HideSelection = False
TreeView1.LabelEdit = tvwManual
End Sub
Private Function GetNextKey() As String
Dim sNewKey As String
Dim iHold As Integer
Dim i As Integer
On Error GoTo myerr
iHold = Val(TreeView1.Nodes(1).Key)
For i = 1 To TreeView1.Nodes.Count
If Val(TreeView1.Nodes(i).Key) > iHold Then
iHold = Val(TreeView1.Nodes(i).Key)
End If
Next
iHold = iHold + 1
sNewKey = VBA.CStr(iHold) & "_"
GetNextKey = sNewKey
Exit Function
myerr:
GetNextKey = "1_"
End Function
1.循环 Sendmessage 实现滚动多行(参见 ScrollTreeView 过程):
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 WM_VSCROLL = &H115
Private Const WM_HSCROLL = &H114
Public Enum MyScrollDirection
sdDown = 0
sdRight = 1
sdUp = 2
sdLeft = 3
End Enum
Public Sub ScrollTreeView(TreeViewX As MSComctlLib.TreeView, Optional DirectionX As MyScrollDirection, Optional Steps As Integer = 1)
Dim i As Long
For i = 0 To Steps - 1
SendMessage TreeViewX.hwnd, VBA.IIf(DirectionX = sdDown Or DirectionX = sdUp, WM_VSCROLL, WM_HSCROLL), VBA.IIf(DirectionX = sdUp Or DirectionX = sdLeft, 0, 1), vbNull
Next i
End Sub
Private Sub Command1_Click()
ScrollTreeView TreeView1, sdRight, 10 '滚动的多点儿
End Sub
Private Sub Form_Load()
Dim i As Integer
TreeView1.Style = tvwTreelinesPlusMinusPictureText
For i = 1 To 50
TreeView1.Nodes.Add , , GetNextKey, "Node " & i
Next i
TreeView1.HideSelection = False
TreeView1.LabelEdit = tvwManual
End Sub
Private Function GetNextKey() As String
Dim sNewKey As String
Dim iHold As Integer
Dim i As Integer
On Error GoTo myerr
iHold = Val(TreeView1.Nodes(1).Key)
For i = 1 To TreeView1.Nodes.Count
If Val(TreeView1.Nodes(i).Key) > iHold Then
iHold = Val(TreeView1.Nodes(i).Key)
End If
Next
iHold = iHold + 1
sNewKey = VBA.CStr(iHold) & "_"
GetNextKey = sNewKey
Exit Function
myerr:
GetNextKey = "1_"
End Function
To playyuer:
1、有没有一个消息可以让Treeview滚动多行?(这还是原来的问题,最好能够这样当然用1也是还是可以的)
3、Treeview的自带的滚动条有没有办法去掉?
2、Treeview的行高是固定的吗?Treeview在做展开、收缩时,其自带滚动条是变化的如何能够得到它的准确的滚动量呢?