共用方式為


TreeView.HotTracking 屬性

定義

會取得或設定一個值,指示樹節點標籤在滑鼠指標經過時是否呈現超連結的外觀。

public:
 property bool HotTracking { bool get(); void set(bool value); };
public bool HotTracking { get; set; }
member this.HotTracking : bool with get, set
Public Property HotTracking As Boolean

屬性值

true如果樹狀節點標籤在滑鼠指標經過時呈現超連結的外觀;否則,。 false 預設值為 false

範例

以下程式碼範例說明了客製化 TreeView的 . 透過繼承該 TreeView 類別,此自訂版本擁有典型 TreeView. 在建構器中改變各種房產價值,能帶來獨特的外觀。 由於屬性 ShowPlusMinus 設定為 false,自訂控制項也會覆寫該 OnAfterSelect 方法,讓點擊節點時可以展開或收斂。

以這種方式自訂的控制項可以在整個組織中使用,方便提供一致的介面,而無需在每個專案中指定控制屬性。

public ref class CustomizedTreeView: public TreeView
{
public:
   CustomizedTreeView()
   {

      // Customize the TreeView control by setting various properties.
      BackColor = System::Drawing::Color::CadetBlue;
      FullRowSelect = true;
      HotTracking = true;
      Indent = 34;
      ShowPlusMinus = false;

      // The ShowLines property must be false for the FullRowSelect
      // property to work.
      ShowLines = false;
   }

protected:
   virtual void OnAfterSelect( TreeViewEventArgs^ e ) override
   {
      // Confirm that the user initiated the selection.
      // This prevents the first node from expanding when it is
      // automatically selected during the initialization of
      // the TreeView control.
      if ( e->Action != TreeViewAction::Unknown )
      {
         if ( e->Node->IsExpanded )
         {
            e->Node->Collapse();
         }
         else
         {
            e->Node->Expand();
         }
      }

      
      // Remove the selection. This allows the same node to be
      // clicked twice in succession to toggle the expansion state.
      SelectedNode = nullptr;
   }
};
public class CustomizedTreeView : TreeView
{
    public CustomizedTreeView()
    {
        // Customize the TreeView control by setting various properties.
        BackColor = System.Drawing.Color.CadetBlue;
        FullRowSelect = true;
        HotTracking = true;
        Indent = 34;
        ShowPlusMinus = false;

        // The ShowLines property must be false for the FullRowSelect 
        // property to work.
        ShowLines = false;
    }

    protected override void OnAfterSelect(TreeViewEventArgs e)
    {
        // Confirm that the user initiated the selection.
        // This prevents the first node from expanding when it is
        // automatically selected during the initialization of 
        // the TreeView control.
        if (e.Action != TreeViewAction.Unknown)
        {
            if (e.Node.IsExpanded) 
            {
                e.Node.Collapse();
            }
            else 
            {
                e.Node.Expand();
            }
        }

        // Remove the selection. This allows the same node to be
        // clicked twice in succession to toggle the expansion state.
        SelectedNode = null;
    }
}
Public Class CustomizedTreeView
    Inherits TreeView

    Public Sub New()
        ' Customize the TreeView control by setting various properties.
        BackColor = System.Drawing.Color.CadetBlue
        FullRowSelect = True
        HotTracking = True
        Indent = 34
        ShowPlusMinus = False

        ' The ShowLines property must be false for the FullRowSelect 
        ' property to work.
        ShowLines = False
    End Sub


    Protected Overrides Sub OnAfterSelect(ByVal e As TreeViewEventArgs)
        ' Confirm that the user initiated the selection.
        ' This prevents the first node from expanding when it is
        ' automatically selected during the initialization of 
        ' the TreeView control.
        If e.Action <> TreeViewAction.Unknown Then
            If e.Node.IsExpanded Then
                e.Node.Collapse()
            Else
                e.Node.Expand()
            End If
        End If

        ' Remove the selection. This allows the same node to be
        ' clicked twice in succession to toggle the expansion state.
        SelectedNode = Nothing
    End Sub

End Class

備註

CheckBoxes 屬性設為 true,則 HotTracking 該屬性不影響。

備註

當屬性 HotTracking 設定為 true時,每個樹節點標籤在滑鼠指標上方時會呈現超連結的外觀。 Underline字型樣式套用到 ,Font並將 ForeColor 設為藍色,讓標籤看起來像連結。 外觀不是由使用者作業系統的網路設定所控制。

適用於