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 ,才會出現在根樹狀節點旁的加號和減號按鈕。 如果未顯示加號和減號按鈕,則沒有任何視覺提示可指出樹狀節點包含子樹狀節點且可展開。 然後,使用者必須按兩下樹狀節點,以判斷它是否包含子樹狀目錄節點、展開子樹狀節點,或將其折迭。