DiagramControl.CustomDrawItem Event

Provides the ability to customize the appearance of diagram items.

Namespace: DevExpress.XtraDiagram

Assembly: DevExpress.XtraDiagram.v20.1.dll

Declaration

[DiagramCategory(DiagramCategory.DiagramPaint)]
public event EventHandler<CustomDrawItemEventArgs> CustomDrawItem
<DiagramCategory(DiagramCategory.DiagramPaint)>
Public Event CustomDrawItem As EventHandler(Of CustomDrawItemEventArgs)

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.
GraphicsCache Returns an object that provides painting facilities.
Item Gets the processed diagram item.
Size Gets the item size.

Remarks

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.

NOTE

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.

Examples

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.

NOTE

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>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
See Also