Export (0) Print
Expand All

TreeView.HotTracking Property

Gets or sets a value indicating whether a tree node label takes on the appearance of a hyperlink as the mouse pointer passes over it.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public bool HotTracking { get; set; }

Property Value

Type: System.Boolean
true if a tree node label takes on the appearance of a hyperlink as the mouse pointer passes over it; otherwise, false. The default is false.

If the CheckBoxes property is set to true, the HotTracking property has no effect.

NoteNote

When the HotTracking property is set to true, each tree node label takes on the appearance of a hyperlink as the mouse pointer passes over it. The Underline font style is applied to the Font and the ForeColor is set to blue to make the label appear as a link. The appearance is not controlled by the Internet settings of the user's operating system.

The following code example illustrates a customized TreeView. By inheriting the TreeView class, this custom version has all the functionality of a typical TreeView. Changing various property values in the constructor provides a unique appearance. Because the ShowPlusMinus property is set to false, the customized control also overrides the OnAfterSelect method so that nodes can be expanded and collapsed when they are clicked.

A control that is customized in this way can be used throughout an organization, making it easy to provide a consistent interface without requiring the control properties to be specified in each individual project.

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;
    }

}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft