TreeNodeStyle.NodeSpacing 屬性

定義

取得或設定套用 TreeNodeStyle 物件之節點與其相鄰節點之間的垂直間距。

public:
 property System::Web::UI::WebControls::Unit NodeSpacing { System::Web::UI::WebControls::Unit get(); void set(System::Web::UI::WebControls::Unit value); };
public System.Web.UI.WebControls.Unit NodeSpacing { get; set; }
member this.NodeSpacing : System.Web.UI.WebControls.Unit with get, set
Public Property NodeSpacing As Unit

屬性值

套用 TreeNodeStyle 之節點與相同層級之相鄰節點之間的垂直間距 (單位為像素), 預設值為 0 圖元。

例外狀況

選取的值具有 Percentage 型別或是小於 0

範例

下列程式碼範例示範如何使用 NodeSpacing 屬性來指定節點與其位於樹狀結構相同層級之相鄰節點之間的垂直間距。


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void HorizontalPadding_Changed(Object sender, EventArgs e)
  {

    // Programmatically set the HorizontalPadding property based on the 
    // user's selection.
    ItemsTreeView.ParentNodeStyle.HorizontalPadding = Convert.ToInt32(HorizontalPaddingList.SelectedItem.Text);

  }

  void VerticalPadding_Changed(Object sender, EventArgs e)
  {

    // Programmatically set the VerticalPadding property based on the 
    // user's selection.
    ItemsTreeView.ParentNodeStyle.VerticalPadding = Convert.ToInt32(VerticalPaddingList.SelectedItem.Text);

  }

  void NodeSpacing_Changed(Object sender, EventArgs e)
  {

    // Programmatically set the NodeSpacing property based on the 
    // user's selection.
    ItemsTreeView.ParentNodeStyle.NodeSpacing = Convert.ToInt32(NodeSpacingList.SelectedItem.Text);

  }

  void ChildNodePadding_Changed(Object sender, EventArgs e)
  {

    // Programmatically set the ChildNodesPadding property based on the 
    // user's selection.
    ItemsTreeView.ParentNodeStyle.ChildNodesPadding = Convert.ToInt32(ChildNodesPaddingList.SelectedItem.Text);

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeStyle Example</title>
</head>
<body>  
    <form id="form1" runat="server">
    
      <h3>TreeNodeStyle Example</h3>
      
      <!-- Set the styles for the leaf nodes declaratively. -->
      <asp:TreeView id="ItemsTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        ParentNodeStyle-ForeColor="Green"
        ParentNodeStyle-HorizontalPadding="5" 
        ParentNodeStyle-VerticalPadding="5"  
        ParentNodeStyle-NodeSpacing="5"
        ParentNodeStyle-ChildNodesPadding="5"
        ExpandDepth="4"  
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Text="Table of Contents"
            SelectAction="None">
             
            <asp:TreeNode Text="Chapter One">
            
              <asp:TreeNode Text="Section 1.0">
              
                <asp:TreeNode Text="Topic 1.0.1"/>
                <asp:TreeNode Text="Topic 1.0.2"/>
                <asp:TreeNode Text="Topic 1.0.3"/>
              
              </asp:TreeNode>
              
              <asp:TreeNode Text="Section 1.1">
              
                <asp:TreeNode Text="Topic 1.1.1"/>
                <asp:TreeNode Text="Topic 1.1.2"/>
                <asp:TreeNode Text="Topic 1.1.3"/>
                <asp:TreeNode Text="Topic 1.1.4"/>
              
              </asp:TreeNode>
            
            </asp:TreeNode>
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>
      
      <hr />
      
      <h5>Select the style settings for the parent nodes.</h5>
      
      <table cellpadding="5">
      
        <tr align="right">
        
          <td>
          
            Horizontal Padding:
          
            <asp:DropDownList id="HorizontalPaddingList"
              AutoPostBack="true"
              OnSelectedIndexChanged="HorizontalPadding_Changed" 
              runat="server">
              
              <asp:ListItem>0</asp:ListItem>
              <asp:ListItem Selected="true">5</asp:ListItem>
              <asp:ListItem>10</asp:ListItem>
              
            </asp:DropDownList> 
          
          </td>
          
          <td>
          
            Vertical Padding:
          
            <asp:DropDownList id="VerticalPaddingList"
              AutoPostBack="true"
              OnSelectedIndexChanged="VerticalPadding_Changed" 
              runat="server">
              
              <asp:ListItem>0</asp:ListItem>
              <asp:ListItem Selected="true">5</asp:ListItem>
              <asp:ListItem>10</asp:ListItem>
              
            </asp:DropDownList> 
          
          </td>
          
        </tr>
        
        <tr align="right">
        
          <td>
          
            Node Spacing:
          
            <asp:DropDownList id="NodeSpacingList"
              AutoPostBack="true"
              OnSelectedIndexChanged="NodeSpacing_Changed"   
              runat="server">
              
              <asp:ListItem>0</asp:ListItem>
              <asp:ListItem Selected="true">5</asp:ListItem>
              <asp:ListItem>10</asp:ListItem>
              
            </asp:DropDownList> 
          
          </td>
          
          <td>
          
            Child Nodes Padding:
          
            <asp:DropDownList id="ChildNodesPaddingList"
              AutoPostBack="true"
              OnSelectedIndexChanged="ChildNodePadding_Changed"  
              runat="server">
              
              <asp:ListItem>0</asp:ListItem>
              <asp:ListItem Selected="true">5</asp:ListItem>
              <asp:ListItem>10</asp:ListItem>
              
            </asp:DropDownList> 
          
          </td>
        
        </tr>
      
      </table>
       
    </form>
  </body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub HorizontalPadding_Changed(ByVal sender As Object, ByVal e As EventArgs)

    ' Programmatically set the HorizontalPadding property based on the 
    ' user's selection.
    ItemsTreeView.ParentNodeStyle.HorizontalPadding = Convert.ToInt32(HorizontalPaddingList.SelectedItem.Text)

  End Sub

  Sub VerticalPadding_Changed(ByVal sender As Object, ByVal e As EventArgs)

    ' Programmatically set the VerticalPadding property based on the 
    ' user's selection.
    ItemsTreeView.ParentNodeStyle.VerticalPadding = Convert.ToInt32(VerticalPaddingList.SelectedItem.Text)

  End Sub

  Sub NodeSpacing_Changed(ByVal sender As Object, ByVal e As EventArgs)

    ' Programmatically set the NodeSpacing property based on the 
    ' user's selection.
    ItemsTreeView.ParentNodeStyle.NodeSpacing = Convert.ToInt32(NodeSpacingList.SelectedItem.Text)

  End Sub

  Sub ChildNodePadding_Changed(ByVal sender As Object, ByVal e As EventArgs)

    ' Programmatically set the ChildNodesPadding property based on the 
    ' user's selection.
    ItemsTreeView.ParentNodeStyle.ChildNodesPadding = Convert.ToInt32(ChildNodesPaddingList.SelectedItem.Text)

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeStyle Example</title>
</head>
<body>  
    <form id="form1" runat="server">
    
      <h3>TreeNodeStyle Example</h3>
      
      <!-- Set the styles for the leaf nodes declaratively. -->
      <asp:TreeView id="ItemsTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        ParentNodeStyle-ForeColor="Green"
        ParentNodeStyle-HorizontalPadding="5" 
        ParentNodeStyle-VerticalPadding="5"  
        ParentNodeStyle-NodeSpacing="5"
        ParentNodeStyle-ChildNodesPadding="5"
        ExpandDepth="4"  
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Text="Table of Contents"
            SelectAction="None">
             
            <asp:TreeNode Text="Chapter One">
            
              <asp:TreeNode Text="Section 1.0">
              
                <asp:TreeNode Text="Topic 1.0.1"/>
                <asp:TreeNode Text="Topic 1.0.2"/>
                <asp:TreeNode Text="Topic 1.0.3"/>
              
              </asp:TreeNode>
              
              <asp:TreeNode Text="Section 1.1">
              
                <asp:TreeNode Text="Topic 1.1.1"/>
                <asp:TreeNode Text="Topic 1.1.2"/>
                <asp:TreeNode Text="Topic 1.1.3"/>
                <asp:TreeNode Text="Topic 1.1.4"/>
              
              </asp:TreeNode>
            
            </asp:TreeNode>
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>
      
      <hr />
      
      <h5>Select the style settings for the parent nodes.</h5>
      
      <table cellpadding="5">
      
        <tr align="right">
        
          <td>
          
            Horizontal Padding:
          
            <asp:DropDownList id="HorizontalPaddingList"
              AutoPostBack="true"
              OnSelectedIndexChanged="HorizontalPadding_Changed" 
              runat="server">
              
              <asp:ListItem>0</asp:ListItem>
              <asp:ListItem Selected="true">5</asp:ListItem>
              <asp:ListItem>10</asp:ListItem>
              
            </asp:DropDownList> 
          
          </td>
          
          <td>
          
            Vertical Padding:
          
            <asp:DropDownList id="VerticalPaddingList"
              AutoPostBack="true"
              OnSelectedIndexChanged="VerticalPadding_Changed" 
              runat="server">
              
              <asp:ListItem>0</asp:ListItem>
              <asp:ListItem Selected="true">5</asp:ListItem>
              <asp:ListItem>10</asp:ListItem>
              
            </asp:DropDownList> 
          
          </td>
          
        </tr>
        
        <tr align="right">
        
          <td>
          
            Node Spacing:
          
            <asp:DropDownList id="NodeSpacingList"
              AutoPostBack="true"
              OnSelectedIndexChanged="NodeSpacing_Changed"   
              runat="server">
              
              <asp:ListItem>0</asp:ListItem>
              <asp:ListItem Selected="true">5</asp:ListItem>
              <asp:ListItem>10</asp:ListItem>
              
            </asp:DropDownList> 
          
          </td>
          
          <td>
          
            Child Nodes Padding:
          
            <asp:DropDownList id="ChildNodesPaddingList"
              AutoPostBack="true"
              OnSelectedIndexChanged="ChildNodePadding_Changed"  
              runat="server">
              
              <asp:ListItem>0</asp:ListItem>
              <asp:ListItem Selected="true">5</asp:ListItem>
              <asp:ListItem>10</asp:ListItem>
              
            </asp:DropDownList> 
          
          </td>
        
        </tr>
      
      </table>
       
    </form>
  </body>
</html>

備註

NodeSpacing使用 屬性來控制套用至 的節點 TreeNodeStyle 與其相鄰節點在相同層級之間的垂直間距量。 這個空間會插入目前節點的上邊緣和上一個節點的下邊緣,以及目前節點的下邊緣與下一個節點的上邊緣之間。 控制項中 TreeView 第一個節點的上方空間不會轉譯,因為這樣會在控制項頂端留下不必要的間距。

NodeSpacingChildNodesPadding 屬性會獨立套用。 節點是否展開不會影響節點間距。

此屬性的值會儲存在檢視狀態中。

適用於

另請參閱