TreeView.ShowPlusMinus 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,用以指示是否在包含子树节点的树节点旁显示加号 (+) 和减号 (-) 按钮。
public:
property bool ShowPlusMinus { bool get(); void set(bool value); };
public bool ShowPlusMinus { get; set; }
member this.ShowPlusMinus : bool with get, set
Public Property ShowPlusMinus As Boolean
属性值
如果在包含子树节点的树节点旁显示加号和减号按钮,则为 true
;否则为 false
。 默认值为 true
。
示例
下面的代码示例演示了自定义 TreeView的 。 通过继承 TreeView 类,此自定义版本具有典型 TreeView的所有功能。 更改构造函数中的各种属性值可提供独特的外观。 由于属性 ShowPlusMinus 设置为 false,因此自定义控件还会重写 OnAfterSelect 该方法,以便在单击节点时可以展开和折叠节点。
可以通过这种方式自定义的控件在整个组织中使用,因此可以轻松提供一致的界面,而无需在每个单独的项目中指定控件属性。
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
注解
仅当属性值为 true
时ShowRootLines,根树节点旁边才会显示加号和减号按钮。 如果未显示加号和减号按钮,则不存在视觉提示以指示树节点包含子树节点且可展开。 然后,用户必须双击树节点以确定它是否包含子树节点、展开它或折叠它。