TreeViewEventArgs-Klasse
Stellt Daten für das AfterCheck-Ereignis, das AfterCollapse-Ereignis, das AfterExpand-Ereignis oder das AfterSelect-Ereignis eines TreeView-Steuerelements bereit.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public Class TreeViewEventArgs
Inherits EventArgs
'Usage
Dim instance As TreeViewEventArgs
public class TreeViewEventArgs : EventArgs
public ref class TreeViewEventArgs : public EventArgs
public class TreeViewEventArgs extends EventArgs
public class TreeViewEventArgs extends EventArgs
Hinweise
Weitere Informationen über die Behandlung von Ereignissen finden Sie unter Behandeln von Ereignissen.
Beispiel
Im folgenden Beispiel wird eine angepasste TreeView veranschaulicht. Durch Vererben der TreeView-Klasse besitzt diese benutzerdefinierte Version den gesamten Funktionsumfang einer normalen TreeView. Durch Ändern verschiedener Eigenschaftenwerte im Konstruktor erreichen Sie eine individuelle Darstellung. Da die ShowPlusMinus-Eigenschaft auf false festgelegt ist, überschreibt das angepasste Steuerelement auch die OnAfterSelect-Methode, sodass Knoten durch Klicken erweitert und reduziert werden können.
Auf diese Weise angepasste Steuerelemente können organisationsweit verwendet werden. Sie können so eine konsistente Oberfläche bereitstellen, ohne dass die Eigenschaften des Steuerelements in jedem einzelnen Projekt angegeben werden müssen.
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
Vererbungshierarchie
System.Object
System.EventArgs
System.Windows.Forms.TreeViewEventArgs
Threadsicherheit
Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
TreeViewEventArgs-Member
System.Windows.Forms-Namespace
TreeViewCancelEventArgs-Klasse