在下面的示例中,文本文件位置的路径设置是 My Documents 文件夹。这样做是因为假定大多数运行 Windows 操作系统的计算机都包含此目录。这还将允许具有最低系统访问级别的用户安全地运行应用程序。
Visual Basic 复制代码
' You should replace the bold text file
' in the sample below with a text file of your own choosing.
TreeView1.Nodes.Add(New myTreeNode (System.Environment.GetFolderPath _
(System.Environment.SpecialFolder.Personal) _
& "\ TextFile.txt ") )
C# 复制代码
// You should replace the bold text file
// in the sample below with a text file of your own choosing.
// Note the escape character used (@) when specifying the path.
treeView1.Nodes.Add(new myTreeNode (System.Environment.GetFolderPath _
(System.Environment.SpecialFolder.Personal) _
+ @"\TextFile.txt") );
C++ 复制代码
// You should replace the bold text file
// in the sample below with a text file of your own choosing.
treeView1->Nodes->Add(new myTreeNode(String::Concat(
System::Environment::GetFolderPath
(System::Environment::SpecialFolder::Personal),
"\\TextFile.txt")));
Visual Basic 复制代码
Public Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Dim mynode As myTreeNode
mynode = CType(e.node, myTreeNode)
MessageBox.Show("Node selected is " & mynode.filepath)
End Sub