TreeView.PathSeparator 属性

获取或设置树节点路径所使用的分隔符串。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property PathSeparator As String
用法
Dim instance As TreeView
Dim value As String

value = instance.PathSeparator

instance.PathSeparator = value
public string PathSeparator { get; set; }
public:
property String^ PathSeparator {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_PathSeparator ()

/** @property */
public void set_PathSeparator (String value)
public function get PathSeparator () : String

public function set PathSeparator (value : String)

属性值

树节点 TreeNode.FullPath 属性所使用的分隔符串。默认为反斜杠字符 (\)。

备注

树节点路径包括一组由 PathSeparator 分隔符串分隔的树节点标签。标签的范围为根树节点到所需的树节点。

示例

下面的代码示例设置 TreeViewPathSeparator 属性,并显示 SelectedNodeTreeNodeCollection 中包含的子树节点数。还显示树视图控件中子树节点占全部树节点的百分比。本示例要求有一个包含 ButtonForm 和一个包含 TreeNodeCollectionTreeView 控件,该集合包含若干个(最好是具有三级或三级以上的)TreeNode 对象。

Private Sub myButton_Click(ByVal sender As Object, _
  ByVal e As System.EventArgs) Handles myButton.Click
   ' Set the tre view's PathSeparator property.
   myTreeView.PathSeparator = "."

   ' Get the count of the child tree nodes contained in the SelectedNode.
   Dim myNodeCount As Integer = myTreeView.SelectedNode.GetNodeCount(True)
   Dim myChildPercentage As Decimal = CDec(myNodeCount) / _
      CDec(myTreeView.GetNodeCount(True)) * 100

   ' Display the tree node path and the number of child nodes it and the tree view have.
   MessageBox.Show(("The '" + myTreeView.SelectedNode.FullPath + "' node has " _
      + myNodeCount.ToString() + " child nodes." + Microsoft.VisualBasic.ControlChars.Lf _
      + "That is " + String.Format("{0:###.##}", myChildPercentage) _
      + "% of the total tree nodes in the tree view control."))
End Sub
private void myButton_Click(object sender, System.EventArgs e)
{
   // Set the tre view's PathSeparator property.
   myTreeView.PathSeparator = ".";

   // Get the count of the child tree nodes contained in the SelectedNode.
   int myNodeCount = myTreeView.SelectedNode.GetNodeCount(true);
   decimal myChildPercentage = ((decimal)myNodeCount/
     (decimal)myTreeView.GetNodeCount(true)) * 100;

   // Display the tree node path and the number of child nodes it and the tree view have.
   MessageBox.Show("The '" + myTreeView.SelectedNode.FullPath + "' node has " 
     + myNodeCount.ToString() + " child nodes.\nThat is " 
     + string.Format("{0:###.##}", myChildPercentage) 
     + "% of the total tree nodes in the tree view control.");
}
void myButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   
   // Set the tre view's PathSeparator property.
   myTreeView->PathSeparator = ".";
   
   // Get the count of the child tree nodes contained in the SelectedNode.
   int myNodeCount = myTreeView->SelectedNode->GetNodeCount( true );
   Decimal myChildPercentage = ((Decimal)myNodeCount / (Decimal)myTreeView->GetNodeCount( true )) * 100;
   
   // Display the tree node path and the number of child nodes it and the tree view have.
   MessageBox::Show( String::Concat( "The '", myTreeView->SelectedNode->FullPath, "' node has ", myNodeCount, " child nodes.\nThat is ", String::Format( "{0:###.##}", myChildPercentage ), "% of the total tree nodes in the tree view control." ) );
}
private void myButton_Click(Object sender, System.EventArgs e)
{
    // Set the tre view's PathSeparator property.
    myTreeView.set_PathSeparator(".");
    // Get the count of the child tree nodes contained in the SelectedNode.
    int myNodeCount = myTreeView.get_SelectedNode().GetNodeCount(true);
    System.Decimal myChildPercentage =
        Decimal.Multiply(Decimal.Divide(new Decimal(myNodeCount),
        new Decimal(myTreeView.GetNodeCount(true))), new Decimal(100));
    // Display the tree node path and the number of child nodes it and the
    // tree view have.
    MessageBox.Show("The '" + myTreeView.get_SelectedNode().get_FullPath()
        + "' node has " + ((Int32)myNodeCount).ToString()
        + " child nodes.\nThat is " + String.Format("{0:###.##}",
        myChildPercentage)
        + "% of the total tree nodes in the tree view control.");
} //myButton_Click

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

TreeView 类
TreeView 成员
System.Windows.Forms 命名空间
TreeNode.FullPath 属性