TreeNodeStates Enumeration
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Definiert Konstanten, die die möglichen Zustände eines TreeNodedarstellen.
Diese Enumeration unterstützt eine bitweise Kombination ihrer Memberwerte.
public enum class TreeNodeStates
[System.Flags]
public enum TreeNodeStates
[<System.Flags>]
type TreeNodeStates =
Public Enum TreeNodeStates
- Vererbung
- Attribute
Felder
| Name | Wert | Beschreibung |
|---|---|---|
| Selected | 1 | Der Knoten ist ausgewählt. |
| Grayed | 2 | Der Knoten ist deaktiviert. |
| Checked | 8 | Der Knoten wird überprüft. |
| Focused | 16 | Der Knoten hat den Fokus. |
| Default | 32 | Der Knoten befindet sich im Standardzustand. |
| Hot | 64 | Der Knoten ist heiß. Dieser Zustand tritt auf, wenn die HotTracking Eigenschaft auf den Knoten festgelegt |
| Marked | 128 | Der Knoten ist markiert. |
| Indeterminate | 256 | Der Knoten in einem unbestimmten Zustand. |
| ShowKeyboardCues | 512 | Der Knoten sollte eine Tastenkombination angeben. |
Beispiele
Das folgende Beispiel veranschaulicht das Anpassen eines Steuerelements mithilfe der TreeView Besitzerzeichnung. Das TreeView Steuerelement im Beispiel zeigt optionale Knotentags zusammen mit den normalen Knotenbeschriftungen an. Knotentags werden mithilfe der TreeNode.Tag Eigenschaft angegeben. Das TreeView Steuerelement verwendet auch benutzerdefinierte Farben, einschließlich einer benutzerdefinierten Hervorhebungsfarbe.
Sie können die TreeView meisten Farben anpassen, indem Sie Farbeigenschaften festlegen, die Auswahlmarkierungsfarbe ist jedoch nicht als Eigenschaft verfügbar. Darüber hinaus erstreckt sich das Standardmäßige Markierungsmarkierungsrechteck nur um eine Knotenbezeichnung. Die Besitzerzeichnung muss zum Zeichnen der Knotentags und zum Zeichnen eines angepassten Hervorhebungsrechtecks verwendet werden, das groß genug ist, um ein Knotentag einzuschließen.
Im Beispiel zeichnet ein Handler für das TreeView.DrawNode Ereignis nicht ausgewählte Knoten durch Aufrufen von Methoden der DrawTreeNodeEventArgs Klasse. Diese Methoden stellen die Standarddarstellung für TreeView Elemente bereit, die keine Anpassung benötigen. Der Handler zeichnet die Knotentags und die benutzerdefinierte Auswahlmarkierung manuell.
Das vollständige Beispiel finden Sie im TreeView.DrawNode Referenzthema.
// Draws a node.
private:
void myTreeView_DrawNode( Object^ sender, DrawTreeNodeEventArgs^ e )
{
// Draw the background and node text for a selected node.
if ( (e->State & TreeNodeStates::Selected) != (TreeNodeStates)0 )
{
// Draw the background of the selected node. The NodeBounds
// method makes the highlight rectangle large enough to
// include the text of a node tag, if one is present.
e->Graphics->FillRectangle( Brushes::Green, NodeBounds( e->Node ) );
// Retrieve the node font. If the node font has not been set,
// use the TreeView font.
System::Drawing::Font^ nodeFont = e->Node->NodeFont;
if ( nodeFont == nullptr )
nodeFont = (dynamic_cast<TreeView^>(sender))->Font;
// Draw the node text.
e->Graphics->DrawString( e->Node->Text, nodeFont, Brushes::White, Rectangle::Inflate( e->Bounds, 2, 0 ) );
}
// Use the default background and node text.
else
{
e->DrawDefault = true;
}
// If a node tag is present, draw its string representation
// to the right of the label text.
if ( e->Node->Tag != nullptr )
{
e->Graphics->DrawString( e->Node->Tag->ToString(), tagFont, Brushes::Yellow, (float)e->Bounds.Right + 2, (float)e->Bounds.Top );
}
// If the node has focus, draw the focus rectangle large, making
// it large enough to include the text of the node tag, if present.
if ( (e->State & TreeNodeStates::Focused) != (TreeNodeStates)0 )
{
Pen^ focusPen = gcnew Pen( Color::Black );
try
{
focusPen->DashStyle = System::Drawing::Drawing2D::DashStyle::Dot;
Rectangle focusBounds = NodeBounds( e->Node );
focusBounds.Size = System::Drawing::Size( focusBounds.Width - 1, focusBounds.Height - 1 );
e->Graphics->DrawRectangle( focusPen, focusBounds );
}
finally
{
if ( focusPen )
delete safe_cast<IDisposable^>(focusPen);
}
}
}
// Draws a node.
private void myTreeView_DrawNode(
object sender, DrawTreeNodeEventArgs e)
{
// Draw the background and node text for a selected node.
if ((e.State & TreeNodeStates.Selected) != 0)
{
// Draw the background of the selected node. The NodeBounds
// method makes the highlight rectangle large enough to
// include the text of a node tag, if one is present.
e.Graphics.FillRectangle(Brushes.Green, NodeBounds(e.Node));
// Retrieve the node font. If the node font has not been set,
// use the TreeView font.
Font nodeFont = e.Node.NodeFont;
if (nodeFont == null) nodeFont = ((TreeView)sender).Font;
// Draw the node text.
e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White,
Rectangle.Inflate(e.Bounds, 2, 0));
}
// Use the default background and node text.
else
{
e.DrawDefault = true;
}
// If a node tag is present, draw its string representation
// to the right of the label text.
if (e.Node.Tag != null)
{
e.Graphics.DrawString(e.Node.Tag.ToString(), tagFont,
Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top);
}
// If the node has focus, draw the focus rectangle large, making
// it large enough to include the text of the node tag, if present.
if ((e.State & TreeNodeStates.Focused) != 0)
{
using (Pen focusPen = new Pen(Color.Black))
{
focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
Rectangle focusBounds = NodeBounds(e.Node);
focusBounds.Size = new Size(focusBounds.Width - 1,
focusBounds.Height - 1);
e.Graphics.DrawRectangle(focusPen, focusBounds);
}
}
}
' Draws a node.
Private Sub myTreeView_DrawNode(ByVal sender As Object, _
ByVal e As DrawTreeNodeEventArgs) Handles myTreeView.DrawNode
' Draw the background and node text for a selected node.
If (e.State And TreeNodeStates.Selected) <> 0 Then
' Draw the background of the selected node. The NodeBounds
' method makes the highlight rectangle large enough to
' include the text of a node tag, if one is present.
e.Graphics.FillRectangle(Brushes.Green, NodeBounds(e.Node))
' Retrieve the node font. If the node font has not been set,
' use the TreeView font.
Dim nodeFont As Font = e.Node.NodeFont
If nodeFont Is Nothing Then
nodeFont = CType(sender, TreeView).Font
End If
' Draw the node text.
e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, _
e.Bounds.Left - 2, e.Bounds.Top)
' Use the default background and node text.
Else
e.DrawDefault = True
End If
' If a node tag is present, draw its string representation
' to the right of the label text.
If (e.Node.Tag IsNot Nothing) Then
e.Graphics.DrawString(e.Node.Tag.ToString(), tagFont, _
Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top)
End If
' If the node has focus, draw the focus rectangle large, making
' it large enough to include the text of the node tag, if present.
If (e.State And TreeNodeStates.Focused) <> 0 Then
Dim focusPen As New Pen(Color.Black)
Try
focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
Dim focusBounds As Rectangle = NodeBounds(e.Node)
focusBounds.Size = New Size(focusBounds.Width - 1, _
focusBounds.Height - 1)
e.Graphics.DrawRectangle(focusPen, focusBounds)
Finally
focusPen.Dispose()
End Try
End If
End Sub
Hinweise
Diese Aufzählung wird von der State Eigenschaft der DrawTreeNodeEventArgs Klasse verwendet. Weitere Informationen finden Sie im TreeView.DrawNode Ereignis.