|
看了下对象的资料,找到了hitest方法,居然又扯出一个x,y坐标转换。- Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nindex As Long) As Long
- Private PixX2TwipX As Double '像素转换成缇
- Private PixX2TwipY As Double
- Private Const LOGPIXELSX = 88
- Private Const LOGPIXELSY = 90
- Private Sub TreeView1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS)
- Dim node As node
- Set node = TreeView1.HitTest(x * PixX2TwipX, y * PixX2TwipY)
- If node Is Nothing Then Exit Sub
- If node.Children > 0 Then
- node.Expanded = True
- End If
- End Sub
- Private Sub UserForm_Initialize()
- Dim Nodx As node, c1 As String, c2 As String
- TreeView1.ImageList = ImageList1
- Set Nodx = TreeView1.Nodes.Add(, , "总公司", "总公司人事结构", 1)
- With Sheets("数据源")
- For x = 2 To .Range("B65536").End(xlUp).Row
- c1 = .Cells(x, 1)
- c2 = .Cells(x, 2) & ""
- If Len(c2) = 1 Then
- Set Nodx = TreeView1.Nodes.Add("总公司", tvwChild, "A" & c2, c1 & "(" & c2 & ")", 2)
- ElseIf Len(c2) = 3 Then
- Set Nodx = TreeView1.Nodes.Add("A" & Left(c2, 1), tvwChild, "A" & c2, c1 & "(" & c2 & ")", 3)
- ElseIf Len(Cells(x, 2)) = 6 Then
- Set Nodx = TreeView1.Nodes.Add("A" & Left(c2, 3), tvwChild, "A" & c2, c1 & "(" & c2 & ")", 4)
- End If
- Next
- End With
- PixX2TwipX = Application.InchesToPoints(1) * 20 / GetDeviceCaps(GetDC(0), LOGPIXELSX)
- PixX2TwipY = Application.InchesToPoints(1) * 20 / GetDeviceCaps(GetDC(0), LOGPIXELSY)
- End Sub
复制代码 |
|