TreeView.ShowPlusMinus Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Beolvas vagy beállít egy értéket, amely jelzi, hogy a pluszjel (+) és a mínuszjel (-) gombok megjelennek-e a gyermekfacsomópontokat tartalmazó facsomópontok mellett.
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
Tulajdonság értéke
trueha pluszjel és mínuszjel gomb jelenik meg a gyermekfacsomópontokat tartalmazó facsomópontok mellett; egyéb esetben. false Az alapértelmezett érték a true.
Példák
Az alábbi példakód egy testre szabott TreeViewkódot mutat be. Az osztály öröklésével ez az TreeView egyéni verzió egy tipikus TreeViewfunkcióval rendelkezik. A konstruktor különböző tulajdonságértékeinek módosítása egyedi megjelenést biztosít. Mivel a ShowPlusMinus tulajdonság értéke hamis, a testreszabott vezérlő felülbírálja a metódust is, így a OnAfterSelect csomópontok kibonthatók és összecsukhatók, amikor rákattintanak.
Az ilyen módon testre szabott vezérlők a szervezet egészében használhatók, így egyszerűen konzisztens felületet biztosíthat anélkül, hogy minden egyes projektben meg kellene adni a vezérlőtulajdonságokat.
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
Megjegyzések
A pluszjel és a mínuszjel gomb csak akkor jelenik meg a gyökérfacsomópontok mellett, ha a ShowRootLines tulajdonság értéke .true Ha a pluszjel és a mínuszjel gomb nem jelenik meg, nincs vizuális jelzés, amely azt jelzi, hogy a facsomópont gyermekfacsomópontokat tartalmaz, és bővíthető. A felhasználónak ezután duplán kell kattintania egy facsomópontra annak megállapításához, hogy gyermekfacsomópontokat tartalmaz-e, kibontja vagy összecsukja.