Export (0) Print
Expand All

DrawTreeNodeEventArgs Class

Provides data for the DrawNode event.

System.Object
  System.EventArgs
    System.Windows.Forms.DrawTreeNodeEventArgs

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

type DrawTreeNodeEventArgs =  
    class 
        inherit EventArgs 
    end

The DrawTreeNodeEventArgs type exposes the following members.

  NameDescription
Public methodDrawTreeNodeEventArgsInitializes a new instance of the DrawTreeNodeEventArgs class.
Top

  NameDescription
Public propertyBoundsGets the size and location of the TreeNode to draw.
Public propertyDrawDefaultGets or sets a value indicating whether the TreeNode should be drawn by the operating system rather than being owner drawn.
Public propertyGraphicsGets the Graphics object used to draw the TreeNode.
Public propertyNodeGets the TreeNode to draw.
Public propertyStateGets the current state of the TreeNode to draw.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Use the DrawNode event to customize the appearance of nodes in a TreeView control using owner drawing.

The DrawNode event is raised by a TreeView control when its TreeView.DrawMode property is set to TreeViewDrawMode.OwnerDrawAll or TreeViewDrawMode.OwnerDrawText and a node is displayed or updated. The DrawTreeNodeEventArgs passed to the event handler contains information about the node to draw as well as providing methods to help you draw the node.

Use the State or Node properties to retrieve information about the node to draw. Use the Graphics property to do the actual drawing within the area specified by the Bounds property. To make the operating system draw a node that does not need to be owner drawn, set the DrawDefault property to true.

When the TreeView.DrawMode property is set to TreeViewDrawMode.OwnerDrawText, the area indicated by the Bounds property includes the label portion of the node only. When the TreeView.DrawMode property is set to TreeViewDrawMode.OwnerDrawAll, the Bounds area includes the entire node, including the area typically used for icons, checkboxes, plus and minus signs, and lines connecting the nodes.

The following code example demonstrates how to customize a TreeView control using owner drawing. The TreeView control in the example displays optional node tags alongside the standard node labels. Node tags are specified using the TreeNode.Tag property. The TreeView control also uses custom colors, including a custom highlight color.

You can customize most of the TreeView colors by setting color properties, but the selection highlight color is not available as a property. Additionally, the default selection highlight rectangle extends only around a node label. Owner drawing must be used to draw the node tags and to draw a customized highlight rectangle large enough to include a node tag.

In the example, a handler for the TreeView.DrawNode event draws the node tags and the custom selection highlight manually. Unselected nodes do not need customization. For these, the DrawDefault property is set to true so that they will be drawn by the operating system.

Additionally, a handler for the Control.MouseDown event provides hit-testing. By default, a node can be selected only by clicking the region around its label. The Control.MouseDown event handler selects a node that is clicked anywhere within this region or within the region around a node tag, if present.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft