TreeView.HoverNodeStyle 屬性

定義

取得 TreeNodeStyle 物件的參考,這個物件可讓您設定當滑鼠指標移至節點上時的節點外觀。

public:
 property System::Web::UI::WebControls::Style ^ HoverNodeStyle { System::Web::UI::WebControls::Style ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.Style HoverNodeStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.HoverNodeStyle : System.Web.UI.WebControls.Style
Public ReadOnly Property HoverNodeStyle As Style

屬性值

Style

TreeNodeStyle 的參考,表示當滑鼠指標移至節點上時的節點樣式。

屬性

範例

下列程式碼範例示範如何在滑鼠指標位於節點上方時,使用 HoverNodeStyle 屬性來控制節點的外觀。 若要讓此範例能夠運作,您必須包含 <head> 具有 屬性的 runat="server" 元素。


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

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

  <!-- The HoverNodeStyle property needs this head element to work. -->
  <head runat="server">
    <title>TreeView HoverNodeStyle Example</title>
</head>

  <body>
    <form id="form1" runat="server">
    
      <h3>TreeView HoverNodeStyle Example</h3>
      
      <!-- Declaratively set the HoverNodeStyle settings. --> 
      <asp:TreeView id="LinksTreeView"
        HoverNodeStyle-ForeColor="Green"
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Value="Home" 
            NavigateUrl="Home.aspx" 
            Text="Home"
            Target="Content" 
            Expanded="True">
             
            <asp:TreeNode Value="Page 1" 
              NavigateUrl="Page1.aspx" 
              Text="Page1"
              Target="Content">
               
              <asp:TreeNode Value="Section 1" 
                NavigateUrl="Section1.aspx" 
                Text="Section 1"
                Target="Content"/>
                 
            </asp:TreeNode>              
            
            <asp:TreeNode Value="Page 2" 
              NavigateUrl="Page2.aspx"
              Text="Page 2"
              Target="Content">
               
            </asp:TreeNode> 
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>

    </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">
<html xmlns="http://www.w3.org/1999/xhtml" >

  <!-- The HoverNodeStyle property needs this head element to work. -->
  <head runat="server">
    <title>TreeView HoverNodeStyle Example</title>
</head>

  <body>
    <form id="form1" runat="server">
    
      <h3>TreeView HoverNodeStyle Example</h3>
      
      <!-- Declaratively set the HoverNodeStyle settings. --> 
      <asp:TreeView id="LinksTreeView"
        HoverNodeStyle-ForeColor="Green"
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Value="Home" 
            NavigateUrl="Home.aspx" 
            Text="Home"
            Target="Content" 
            Expanded="True">
             
            <asp:TreeNode Value="Page 1" 
              NavigateUrl="Page1.aspx" 
              Text="Page1"
              Target="Content">
               
              <asp:TreeNode Value="Section 1" 
                NavigateUrl="Section1.aspx" 
                Text="Section 1"
                Target="Content"/>
                 
            </asp:TreeNode>              
            
            <asp:TreeNode Value="Page 2" 
              NavigateUrl="Page2.aspx"
              Text="Page 2"
              Target="Content">
               
            </asp:TreeNode> 
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>

    </form>
  </body>
</html>

備註

HoverNodeStyle當滑鼠指標位於節點上方時,請使用 屬性來控制節點的外觀。 此屬性是唯讀的;不過,您可以設定其傳回之 TreeNodeStyle 物件的屬性。 屬性可以宣告方式在 表單 Property-Subproperty 中設定,其中 Subproperty 是物件的屬性 TreeNodeStyle (例如, HoverNodeStyle-ForeColor) 。 屬性也可以在表單 Property.Subproperty 中以程式設計方式設定,例如 () HoverNodeStyle.ForeColor 。 只有支援腳本的用戶端才支援此功能。

注意

若要使用 HoverNodeStyle 屬性,您必須包含 <head> 具有 屬性的 runat="server" 元素。

常見的設定通常包括自訂背景色彩、前景色彩、字型屬性和節點間距。 樣式屬性會依下列順序套用:

  1. NodeStyle.

  2. RootNodeStyleParentNodeStyle 、 或 LeafNodeStyle ,視節點類型而定。 LevelStyles如果定義集合,則此時會套用它,覆寫其他節點樣式屬性。

  3. SelectedNodeStyle.

  4. HoverNodeStyle.

注意

屬性的 HoverNodeStyle 樣式設定會覆寫 、、 RootNodeStyle ParentNodeStyleLeafNodeStyleSelectedNodeStyle 屬性中 NodeStyle 任何對應的節點樣式設定。

屬性 HoverNodeStyle 不會針對其 SelectAction 屬性設定為 TreeNodeSelectAction.None 的節點轉譯。

ParentNodeStyle不同于 和 LeafNodeStyle 屬性,這些是 TreeNodeStyle 物件, HoverNodeStyle 屬性是 Style 物件。

適用於

另請參閱