System.Windows.Forms.TreeView.DrawNode Event

Occurs when a System.Windows.Forms.TreeView is drawn and the TreeView.DrawMode property is set to a System.Windows.Forms.TreeViewDrawMode value other than TreeViewDrawMode.Normal.

Syntax

public event DrawTreeNodeEventHandler DrawNode

Remarks

Use this event to customize the appearance of nodes in a System.Windows.Forms.TreeView control using owner drawing.

This event is raised only when the TreeView.DrawMode property is set to System.Windows.Forms.TreeViewDrawMode values of TreeViewDrawMode.OwnerDrawAll or TreeViewDrawMode.OwnerDrawText. The following table indicates how the System.Windows.Forms.TreeNode can be customized when the TreeView.DrawMode property is set to these values.

TreeViewDrawMode.OwnerDrawText

The System.Windows.Forms.TreeNode label area can be customized. All other System.Windows.Forms.TreeNode elements are drawn automatically.

TreeViewDrawMode.OwnerDrawAll

The appearance of the entire System.Windows.Forms.TreeNode can be customized. Icons, check boxes, plus and minus signs, and lines connecting the nodes must be drawn manually if they are desired.

The region that the TreeNode.Text value would occupy if it were drawn using the font specified by the System.Windows.Forms.TreeView control's Control.Font property is the region in which a node can be clicked to select it. This is called the hit test region. If you draw outside this region, you should provide your own code that selects a node when its visible area is clicked.

The hit test region corresponds to the DrawTreeNodeEventArgs.Bounds property when using TreeViewDrawMode.OwnerDrawText. When using TreeViewDrawMode.OwnerDrawAll, however, the DrawTreeNodeEventArgs.Bounds property encompasses the entire width of the System.Windows.Forms.TreeView. In this case, you can access the hit test region by getting the DrawTreeNodeEventArgs.Node value and accessing its TreeNode.Bounds property. You can then draw the hit test region of the node within these bounds, or you can provide your own hit test code. Note that setting the TreeNode.NodeFont property does not change the size of the hit test region, which is calculated using the font specified for the entire System.Windows.Forms.TreeView.

For more information about how to handle events, see Consuming Events.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 2.0.0.0