Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim doc As New PrintDoc '定义一个报表
For Each nd As WinForm.TreeNode In trv.AllNodes
Dim rt As New prt.RenderText '定义一个文本对象
If nd.Level = 0 Then
rt.Text = nd.Text
Else
Dim s As String = ""
Dim ad As WinForm.TreeNode = nd.ParentNode
Dim pd As WinForm.TreeNode
If ad.ParentNode IsNot Nothing Then
s = "".PadLeft(6)
pd = ad.ParentNode
End If
Do While pd IsNot Nothing
If pd.Level > 0 Then
If pd.Nodes.Count - 1 = ad.Index Then
s = "".PadLeft(6) & s
Else
s = "".PadLeft(6) & ":" & s
End If
ElseIf trv.Nodes.Count - 1 > pd.Index AndAlso s.StartsWith(":") = False Then
s = ":" & s
End If
ad = pd
pd = pd.ParentNode
Loop
rt.Text = s & ":" & "".PadLeft(4, ".") & nd.Text
End If
doc.Body.Children.Add(rt)
Next
doc.Preview()