All docs
V20.1
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

XtraDiagramExtensions.DrawDetachedItem(DiagramControl, DiagramItem, GraphicsCache) Method

Allows you to draw a diagram item outside the Canvas/Shapes Panel.

Namespace: DevExpress.XtraDiagram.Extensions

Assembly: DevExpress.XtraDiagram.v20.1.dll

Declaration

public static void DrawDetachedItem(
    this DiagramControl diagram,
    DiagramItem diagramItem,
    GraphicsCache graphicsCache
)
<ExtensionAttribute>
Public Shared Sub DrawDetachedItem(
    diagram As DiagramControl,
    diagramItem As DiagramItem,
    graphicsCache As GraphicsCache
)

Parameters

Name Type Description
diagram DiagramControl

A diagram that is the owner of the item.

diagramItem DiagramItem

A diagram item to draw.

graphicsCache GraphicsCache

A GraphicsCache object that provides painting facilities.

Remarks

You can use the DrawDetachedItem method to create a custom Shapes Panel.

The CustomDrawItemEventArgs.Context property returns the DiagramDrawingContext.Detached value for items that are drawn by the DrawDetachedItem method.

The example below illustrates how to generate a bitmap from a diagram item.

using DevExpress.Diagram.Core;
using DevExpress.Utils.Drawing;
using DevExpress.XtraDiagram.Designer;
using DevExpress.XtraDiagram.Extensions;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

public static class BitmapHelper {

    public static void DrawWithGraphics(this Image image, Action<GraphicsCache> draw) {
        using (Graphics graphics = Graphics.FromImage(image)) {
            using (GraphicsCache cache = new GraphicsCache(new DXPaintEventArgs(graphics,
            Rectangle.Truncate(graphics.ClipBounds)))) {
                draw(cache);
            }
        }
    }
}

public void GenerateBitmap() {
    var item = new DiagramShape() { Width = 120, Height = 130, BackgroundId = DiagramThemeColorId.Accent5 };
    using (var stream = new MemoryStream()) {
        using (var bitmap = new Bitmap(200, 200)) {
            bitmap.DrawWithGraphics(cache => {
                cache.TranslateTransform(10, 25);
                Diagram.DrawDetachedItem(item, cache);
            });
            bitmap.Save(stream, ImageFormat.Png);
        }
    }
}

The How to: Create a Custom Toolbox example illustrates the usage of the DrawDetachedItem method.

See Also