TreeView.ShowPlusMinus-Eigenschaft
Ruft einen Wert ab, der angibt, ob neben den Strukturknoten mit untergeordneten Strukturknoten Schaltflächen mit Pluszeichen (+) und Minuszeichen (-) angezeigt werden, oder legt diesen fest.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public Property ShowPlusMinus As Boolean
'Usage
Dim instance As TreeView
Dim value As Boolean
value = instance.ShowPlusMinus
instance.ShowPlusMinus = value
public bool ShowPlusMinus { get; set; }
public:
property bool ShowPlusMinus {
bool get ();
void set (bool value);
}
/** @property */
public boolean get_ShowPlusMinus ()
/** @property */
public void set_ShowPlusMinus (boolean value)
public function get ShowPlusMinus () : boolean
public function set ShowPlusMinus (value : boolean)
Eigenschaftenwert
true, wenn neben den Strukturknoten mit untergeordneten Strukturknoten Schaltflächen mit Pluszeichen (+) und Minuszeichen (-) angezeigt werden, andernfalls false. Der Standardwert ist true.
Hinweise
Die Schaltflächen mit Pluszeichen (+) und Minuszeichen (-) werden nur dann neben den Stammknoten angezeigt, wenn der Wert der ShowRootLines-Eigenschaft true ist. Wenn die Schaltflächen mit Pluszeichen (+) und Minuszeichen (-) nicht angezeigt werden, gibt es keinen sichtbaren Hinweis darauf, dass der Strukturknoten untergeordnete Strukturknoten enthält und erweitert werden kann. In diesem Fall muss durch Doppelklicken auf einen Strukturknoten festgestellt werden, ob dieser untergeordnete Strukturknoten enthält, die erweitert oder reduziert werden können.
Beispiel
Im folgenden Codebeispiel 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 in der gesamten Organisation verwendet werden. Sie können somit 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
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
TreeView-Klasse
TreeView-Member
System.Windows.Forms-Namespace
ShowRootLines