A newer version of this page is available. Switch to the current version.

DiagramControl.CustomDrawItem Event

Provides the ability to customize the appearance of diagram items.

Namespace: DevExpress.XtraDiagram

Assembly: DevExpress.XtraDiagram.v19.1.dll


public event EventHandler<CustomDrawItemEventArgs> CustomDrawItem

Event Data

The CustomDrawItem event's data class is CustomDrawItemEventArgs. The following properties provide information specific to this event:

Property Description
Appearance Provides access to the item’s appearance settings.
Context Returns the value that indicates whether the item is to be drawn on the canvas, toolbox, in the print or export output or as the drag preview.
Graphics Returns an object that provides painting facilities.
Item Gets the processed diagram item.
Size Gets the item size.

The event data class exposes the following methods:

Method Description
DefaultDraw(CustomDrawItemMode) Allows you to define which elements of the default painting should be painted.


The CustomDrawItem event allows you to customize the appearance of diagram items or implement a custom painting from scratch.

Set the Handled parameter to true to disable default painting. Additionally, the CustomDrawItemEventArgs.DefaultDraw method allows you to define which elements of the default painting should be painted.


If the font’s Unit property is not set to GraphicsUnit.Pixel, the font size of the text drawn by the Graphics.DrawString method is scaled based on the DPI settings.


This example demonstrates how to use the DiagramControl.CustomDrawItem event to modify the standard drawing mechanism of diagram items (shapes, connectors, containers, etc.). In this example, a DiagramShape class descendant was created to introduce the Status property. Depending on the Status property value, a custom icon is drawn in the lower right-hand corner of a shape.


The CustomDrawItemEventArgs.DefaultDraw method in the event args invokes certain parts of the standard shape drawing mechanism (the method parameter defines which ones). If you don’t call this method, shape content, border and background will not be drawn.

To apply custom drawing logic defined in the DiagramControl.CustomDrawItem event handler to your shapes, set the Handled property from the event args to true.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace XtraDiagram.CustomDraw {
    static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main() {
            Application.Run(new Form1());
See Also