Skip to content

DevExpress-Examples/winforms-diagram-create-custom-shapes-based-on-diagram-containers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms DiagramControl - Create Custom Shapes Based on Diagram Containers

The following example creates custom DevExpress Diagram shapes (DiagramContainers) with multiple inner shapes. You can use this technique to create custom shapes if/when associated geometries must consist of combined predefined shapes.

image

Implementation Details

To begin, you must:

  1. Create a container and add static non-selectable shapes:

    public DiagramContainer CreateContainerShape1() {
        var container = new DiagramContainer();
        container.Appearance.BorderSize = 0;
        container.Appearance.BackColor = Color.Transparent;
    
        var innerShape1 = new DiagramShape() {
            CanSelect = false,
            CanChangeParent = false,
            CanEdit = false,
            CanCopyWithoutParent = false,
            CanDeleteWithoutParent = false,
            CanMove = false,
            Shape = BasicShapes.Trapezoid,
            Anchors = Sides.Top | Sides.Left | Sides.Right,
            Height = 50,
            Width = 200,
    
            Content = "Custom text"
        };
    
        var innerShape2 = new DiagramShape() {
            CanSelect = false,
            CanChangeParent = false,
            CanEdit = false,
            CanCopyWithoutParent = false,
            CanDeleteWithoutParent = false,
            CanMove = false,
            Shape = BasicShapes.Rectangle,
            Anchors = Sides.All,
            Height = 150,
            Width = 200,
            Position = new DevExpress.Utils.PointFloat(0, 50),
        };
    
        container.Items.Add(innerShape1);
        container.Items.Add(innerShape2);
    
        return container;
    }
  2. Register a FactoryItemTool to create an instance of this container:

    void RegisterStencil() {
        var stencil = new DiagramStencil("CustomStencil", "Custom Shapes");
    
        var itemTool = new FactoryItemTool("CustomShape1",
            () => "Custom Shape 1",
            diagram => CreateContainerShape1(),
            new System.Windows.Size(200, 200), 
            false
        );
    
        stencil.RegisterTool(itemTool);
        DiagramToolboxRegistrator.RegisterStencil(stencil);
    
        diagramControl1.OptionsBehavior.SelectedStencils = new StencilCollection() { "CustomStencil" };
    }

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)