TreeView.HotTracking 属性

定义

获取或设置一个值,用以指示当鼠标指针移过树节点标签时,树节点标签是否具有超链接的外观。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.

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

属性值

Boolean

如果当鼠标指针移过树节点标签时,树节点标签具有超链接的外观,则为 true;否则为 falsetrue if a tree node label takes on the appearance of a hyperlink as the mouse pointer passes over it; otherwise, false. 默认值为 falseThe default is false.

示例

下面的代码示例演示自定义的 TreeViewThe following code example illustrates a customized TreeView. 通过继承 TreeView 类,此自定义版本具有典型的所有功能 TreeViewBy 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. 由于 ShowPlusMinus 属性设置为 false ,因此自定义控件也会重写 OnAfterSelect 方法,以便在单击节点时展开和折叠节点。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 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 属性不起作用。If the CheckBoxes property is set to true, the HotTracking property has no effect.

备注

HotTracking 属性设置为时 true ,每个树节点标签都将在鼠标指针移到超链接上时使用该超链接的外观。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. Underline 字体样式应用到 Font ,并将 ForeColor 设置为蓝色,以使标签显示为链接。The Underline font style is applied to the Font and the ForeColor is set to blue to make the label appear as a link. 此外观不受用户操作系统的 Internet 设置的控制。The appearance is not controlled by the Internet settings of the user's operating system.

适用于