/// <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); } }
/// <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. }