Proprietà TreeView.HotTracking (System.Windows.Forms)

Cambia visualizzazione:
ScriptFree
Riferimento a .NET Framework
Proprietà TreeView.HotTracking

Ottiene o imposta un valore che indica se un'etichetta del nodo della struttura assume l'aspetto di un collegamento ipertestuale al passaggio del mouse su di essa.

Spazio dei nomi: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Sintassi

Visual Basic - (Dichiarazione)
Public Property HotTracking As Boolean
Visual Basic (Utilizzo)
Dim instance As TreeView
Dim value As Boolean

value = instance.HotTracking

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

/** @property */
public void set_HotTracking (boolean value)

JScript
public function get HotTracking () : boolean

public function set HotTracking (value : boolean)

Valore proprietà

true se l'etichetta di un nodo della struttura assume l'aspetto di un collegamento ipertestuale al passaggio del mouse su di essa; in caso contrario, false. Il valore predefinito è false.
Eccezioni

Tipo di eccezione Condizione

ArgumentOutOfRangeException

Il valore impostato è minore di -1.

Note

Se la proprietà CheckBoxes è impostata su true, la proprietà HotTracking non avrà alcun effetto.

NotaNota

Quando la proprietà HotTracking è impostata su true, ciascuna etichetta del nodo della struttura assume l'aspetto di un collegamento ipertestuale al passaggio del mouse su di essa. Lo stile Underline del carattere viene applicato all'oggetto Font mentre la proprietà ForeColor viene impostata su blu affinché l'etichetta assuma l'aspetto di un collegamento ipertestuale. L'aspetto non è determinato dalle impostazioni Internet del sistema operativo dell'utente.

Esempio

Nell'esempio di codice riportato di seguito viene illustrato un oggetto TreeView personalizzato. Ereditando la classe TreeView, questa versione personalizzata dispone di tutta la funzionalità di un oggetto TreeView tipico. La modifica di alcuni valori di proprietà nel costruttore fornisce un aspetto univoco. Poiché la proprietà ShowPlusMinus è impostata su false, il controllo personalizzato esegue anche l'override del metodo OnAfterSelect in modo da consentire l'espansione e la compressione dei nodi quando si fa clic su di essi.

Un controllo personalizzato in questo modo può essere utilizzato in tutta un'organizzazione per fornire agevolmente un'interfaccia coerente senza dover specificare le proprietà del controllo in ogni singolo progetto.

Visual Basic
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 

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

}

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

J#
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 

Piattaforme

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

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.

Informazioni sulla versione

.NET Framework

Supportato in: 2.0 1.1 1.0
Vedere anche