Dim t As WinForm.TreeView = Forms("窗口3").Controls("TreeView1")
t.CollapseAll
t.SelectedNode = t.Nodes(0)
t.ExpandAll
Dim tn As WinForm.TreeNode = t.SelectedNode
Dim level As Integer = 0
For Each n As WinForm.TreeNode In t.AllNodes
If n.Nodes.Count = 0 AndAlso n.Level > level Then
tn = n
level = n.Level
End If
Next
Dim trv = t.BaseControl
Dim rg = trv.rectangletoscreen(tn.BaseNode.bounds)
Dim rg2 = Forms("窗口3").panel.rectangletoscreen(trv.bounds)
If rg.Right > rg2.Right Then
t.width = rg2.width + rg.Right - rg2.Right + 2
End if