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.
To begin, you must:
-
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; }
-
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" }; }
- WinForms DiagramControl - Register FactoryItemTools for Regular and Custom Shapes
- WinForms DiagramControl - Create Rotatable Containers with Shapes
- WinForms DiagramControl - Proportionally Resize Shapes Within the Parent Container
(you will be redirected to DevExpress.com to submit your response)