Skip to main content
A newer version of this page is available. .

How to: Use the CustomDrawItem Event to Draw Custom Icons Inside Diagram Items

  • 4 minutes to read

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());
        }
    }
}