DrawTreeNodeExtendedEventArgs Constructor

Constructor

Definition

Namespace: EWSoftware.ListControls
Assembly: EWSoftware.ListControls (in EWSoftware.ListControls.dll) Version: 2023.4.9.0
public DrawTreeNodeExtendedEventArgs(
	Graphics g,
	TreeNode treeNode,
	TreeNodeStates nodeState,
	Rectangle bounds
)

Parameters

g  Graphics
The graphics object to use
treeNode  TreeNode
The tree node to draw
nodeState  TreeNodeStates
The current node state
bounds  Rectangle
The node's bounds

Example

C# - TreeNodeDrawing Event Handler Example
/// <summary>
/// Test TreeNodeDrawing event handler.  This occurs before the tree
/// view draws the node.
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The event arguments</param>
private void tvExtTree_TreeNodeDrawing(object sender, DrawTreeNodeExtendedEventArgs e)
{
    if(!chkFormDrawNode.Checked)
        return;

    // Use solid 2px lines
    e.LinePen.DashStyle = DashStyle.Solid;
    e.LinePen.Width = 2;

    // Change the text by adding the node name.  Assigning new text
    // automatically recalculates the text and focus bounds. We could
    // draw the text, but we'll let the base class handle it. Note that
    // since the tree view doesn't know about the extra text, it won't
    // show the horizontal scrollbar if it goes off the right edge.
    e.Text += " (" + e.Node.Name + ")";

    // If the item height is larger than 35, wrap the text too
    if(tvExtTree.ItemHeight > 35)
    {
        e.StringFormat.FormatFlags = StringFormatFlags.NoClip;

        // Limit the text to the right edge of the node bounds.  Note
        // that this won't stop the tree view from showing a horizontal
        // scrollbar.
        e.TextBounds = new Rectangle(e.TextBounds.Left, e.NodeBounds.Top,
            e.NodeBounds.Width - e.TextBounds.Left, e.NodeBounds.Height);
    }

    // NOTE:
    // If you choose to draw one or more parts of the node, you should
    // draw the background first, then the node parts, and then turn
    // off the NodeParts.Background flag along with the other node part
    // flags in the e.NodeParts property before returning.
}
C# - TreeNodeDrawn Event Handler Example
/// <summary>
/// Test TreeNodeDrawn event handler.  This occurs after the tree view
/// has drawn the node.
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The event arguments</param>
private void tvExtTree_TreeNodeDrawn(object sender, DrawTreeNodeExtendedEventArgs e)
{
    Pen pen;
    int top;

    if(chkFormDrawNode.Checked && e.Node.Level == 0 && e.ImageIndex != -1)
    {
        // Nothing exciting, we'll just draw a line through
        // top level nodes that have an image index set.
        if((e.State & TreeNodeStates.Focused) != 0 && tvExtTree.FullRowSelect)
            pen = SystemPens.ControlLightLight;
        else
            pen = SystemPens.ControlDarkDark;

        top = e.NodeBounds.Top + (e.NodeBounds.Height / 2);

        e.Graphics.DrawLine(pen, e.NodeBounds.Left, top,
            e.NodeBounds.Left + e.NodeBounds.Width, top);
    }
}
VB.NET - TreeNodeDrawing Event Handler Example
''' <summary>
''' Test TreeNodeDrawing event handler.  This occurs before the tree
''' view draws the node.
''' </summary>
''' <param name="sender">The sender of the event</param>
''' <param name="e">The event arguments</param>
Private Sub tvExtTree_TreeNodeDrawing(ByVal sender As System.Object, _
  ByVal e As EWSoftware.ListControls.DrawTreeNodeExtendedEventArgs) _
  Handles tvExtTree.TreeNodeDrawing
    If Not chkFormDrawNode.Checked Then
        Return
    End If

    ' Use solid 2px lines
    e.LinePen.DashStyle = DashStyle.Solid
    e.LinePen.Width = 2

    ' Change the text by adding the node name.  Assigning new text
    ' automatically recalculates the text and focus bounds. We could
    ' draw the text, but we'll let the base class handle it. Note that
    ' since the tree view doesn't know about the extra text, it won't
    ' show the horizontal scrollbar if it goes off the right edge.
    e.Text += " (" & e.Node.Name & ")"

    ' If the item height is larger than 35, wrap the text too
    If tvExtTree.ItemHeight > 35 Then
        e.StringFormat.FormatFlags = StringFormatFlags.NoClip

        ' Limit the text to the right edge of the node bounds.  Note
        ' that this won't stop the tree view from showing a horizontal
        ' scrollbar.
        e.TextBounds = new Rectangle(e.TextBounds.Left, e.NodeBounds.Top,
            e.NodeBounds.Width - e.TextBounds.Left, e.NodeBounds.Height)
    End If

    ' NOTE:
    ' If you choose to draw one or more parts of the node, you should
    ' draw the background first, then the node parts, and then turn
    ' off the NodeParts.Background flag along with the other node part
    ' flags in the e.NodeParts property before returning.
End Sub
VB.NET - TreeNodeDrawn Event Handler Example
''' <summary>
''' Test TreeNodeDrawn event handler.  This occurs after the tree view
''' has drawn the node.
''' </summary>
''' <param name="sender">The sender of the event</param>
''' <param name="e">The event arguments</param>
Private Sub tvExtTree_TreeNodeDrawn(ByVal sender As System.Object, _
  ByVal e As EWSoftware.ListControls.DrawTreeNodeExtendedEventArgs) _
  Handles tvExtTree.TreeNodeDrawn
    Dim pen As Pen
    Dim top As Integer

    If chkFormDrawNode.Checked And e.Node.Level = 0 And e.ImageIndex <> -1 Then
        ' Nothing exciting, we'll just draw a line through top level nodes
        ' that have an image index set.
        If (e.State And TreeNodeStates.Focused) <> 0 And tvExtTree.FullRowSelect
            pen = SystemPens.ControlLightLight
        Else
            pen = SystemPens.ControlDarkDark
        End If

        top = CType(e.NodeBounds.Top + (e.NodeBounds.Height / 2), Integer)

        e.Graphics.DrawLine(pen, e.NodeBounds.Left, top, _
            e.NodeBounds.Left + e.NodeBounds.Width, top)
    End If
End Sub

See Also