DiagramControl.CustomDrawItem Event
Provides the ability to customize the appearance of diagram items.
Namespace: DevExpress.XtraDiagram
Assembly: DevExpress.XtraDiagram.v24.2.dll
NuGet Package: DevExpress.Win.Diagram
#Declaration
[DiagramCategory(DiagramCategory.DiagramPaint)]
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. |
Decorator | |
Graphics | Returns an object that provides painting facilities. |
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 |
---|---|
Default |
Allows you to define which elements of the default painting should be painted. |
Get |
#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 Graphics
Set the SmoothingMode property to AntiAlias, the CompositingQuality property to HighQuality, and use the DrawPath and FillPath methods to render high quality antialiased text.
#Example
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 Custom
To apply custom drawing logic defined in the Diagram
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());
}
}
}