TreeView.HotTracking 属性

获取或设置一个值,用以指示当鼠标指针移过树节点标签时,树节点标签是否具有超链接的外观。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property HotTracking As Boolean
用法
Dim instance As TreeView
Dim value As Boolean

value = instance.HotTracking

instance.HotTracking = value
public bool HotTracking { get; set; }
public:
property bool HotTracking {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_HotTracking ()

/** @property */
public void set_HotTracking (boolean value)
public function get HotTracking () : boolean

public function set HotTracking (value : boolean)

属性值

如果当鼠标指针移过树节点标签时,树节点标签具有超链接的外观,则为 true;否则为 false。默认为 false

异常

异常类型 条件

ArgumentOutOfRangeException

设置的值小于 -1。

备注

如果 CheckBoxes 属性设置为 trueHotTracking 属性将失效。

提示

如果 HotTracking 属性设置为 true,那么当鼠标指针移过每个树节点标签时,树节点标签都将具有超链接的外观。Underline 字体样式将应用于 FontForeColor 将设置为蓝色,从而使标签显示为链接。这种外观并非由用户操作系统的 Internet 设置来控制。

示例

下面的代码示例演示一个自定义的 TreeView。通过继承 TreeView 类,此自定义版本具有典型 TreeView 的所有功能。在构造函数中更改不同的属性值可以提供独特的外观。由于 ShowPlusMinus 属性设置为 false,因此该自定义控件还重写 OnAfterSelect 方法,以便单击节点时能够展开和折叠它们。

以这种方式自定义的控件可以在整个单位中使用,因此很容易提供一致的界面,而不需要在每个单独的项目中指定控件属性。

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 'New


    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 'OnAfterSelect

End Class 'CustomizedTreeView 
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 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 extends TreeView
{
    public CustomizedTreeView()
    {
        // Customize the TreeView control by setting various properties.
        set_BackColor(System.Drawing.Color.get_CadetBlue());
        set_FullRowSelect(true);
        set_HotTracking(true);
        set_Indent(34);
        set_ShowPlusMinus(false);
        // The ShowLines property must be false for the FullRowSelect 
        // property to work.
        set_ShowLines(false);
    } //CustomizedTreeView

    protected 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.get_Action().Equals(TreeViewAction.Unknown))) {
            if (e.get_Node().get_IsExpanded()) {
                e.get_Node().Collapse();
            }
            else {
                e.get_Node().Expand();
            }
        }
        // Remove the selection. This allows the same node to be
        // clicked twice in succession to toggle the expansion state.
        set_SelectedNode(null);
    } //OnAfterSelect
}//CustomizedTreeView 

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

TreeView 类
TreeView 成员
System.Windows.Forms 命名空间