Skip to main content

Shapes Panel

  • 3 minutes to read

The Shapes panel displays available shapes that users can drag to the Canvas.

shapes

Users can click the Expandchevron2/Collapsechevron1 buttons to toggle between full and compact modes. To change the display mode in code-behind, use the DiagramOptionsBehavior.ToolboxVisibility property. The image below shows the panel in compact mode.

image

Users can select the Shapes Panel item in the Ribbon UI to show or hide the Shapes panel.

win diagram panes

Shapes are organized into categories. The Quick Shapes category contains shapes whose ShapeDescription.IsQuick property is set to true. Set the DiagramOptionsBehavior.ShowQuickShapes property to false to hide the Quick Shapes category.

The search form that is displayed at the top of the panel allows end-users to search a shape by its name. The dropdown button MRU Dropdown Button invokes the list of the most recently used (MRU) search strings.

Customization

Shapes in the Shapes panel are grouped by stencils. Use the DiagramOptionsBehavior.Stencils property to modify stencils for a specific DiagramControl. The following example shows how to create a stencil with an SVG shape:

var svgStencil = new DiagramStencil("SVGStencilId", "SVGStencilName");
using(var svgStream = File.OpenRead("Shape.svg")) {
    var svgShape = ShapeDescription.CreateSvgShape("SVGShapeId", "SVGShapeName", svgStream);
    svgStencil.RegisterShape(svgShape);
}
diagramControl1.OptionsBehavior.Stencils = new DiagramStencilCollection(DiagramToolboxRegistrator.Stencils.Concat(new[] { svgStencil }));

To modify stencils for all diagrams in your application, use the DiagramToolboxRegistrator static class’s DiagramToolboxRegistrator.RegisterStencil and DiagramToolboxRegistrator.UnregisterStencil methods. The example below illustrates how to remove all the default stencils from the Shapes panel.

List<DiagramStencil> Stencils = DiagramToolboxRegistrator.Stencils.ToList<DiagramStencil>();
Stencils.ForEach(s => DiagramToolboxRegistrator.UnregisterStencil(s));

Use FactoryItemTool to Add Items

The FactoryItemTool class allows you to add the DiagramShape, DiagramImage, DiagramContainer, and DiagramConnector items to stencils. The code snippet below illustrates how to add a new stencil with a raster image.

DiagramStencil myStencil = new DiagramStencil("myStencil", "My Stencil");
myStencil.RegisterTool(new FactoryItemTool("customItem", () => "Custom Item",
        diagram => new DiagramImage() { Image = "img.png" }, new Size(100, 100)));
DiagramToolboxRegistrator.RegisterStencil(myStencil);

Modify Existing Items

Use the DiagramControl.ItemInitializing event to modify newly created diagram items and toolbox items. The example below illustrates how to change the border thickness for the Rectangle shape.

private void Diagram_ItemInitializing(object sender, DevExpress.XtraDiagram.DiagramItemInitializingEventArgs e) {
    DiagramShape shapeItem = e.Item as DiagramShape;
    if (shapeItem !=null && shapeItem.Shape == BasicShapes.Rectangle) {
        shapeItem.StrokeThickness = 8;
    }
}

Remove Stencils

To remove a stencil from the Shapes panel, use the DiagramToolboxRegistrator static class’s DiagramToolboxRegistrator.UnregisterStencil method:

 DiagramToolboxRegistrator.UnregisterStencil(SDLDiagramShapes.Stencil);

To remove all stencils except those specified, initialize a new DiagramStencilCollection and set it as the DiagramOptionsBehavior.Stencils property value:

 diagramControl1.Stencils = new
 DevExpress.Diagram.Core.DiagramStencilCollection(BasicShapes.Stencil);

Remove Shapes From Stencils

Use the DiagramStencil.UnregisterShape method to remove a shape from a stencil. See the example below.

 BasicShapes.Stencil.UnregisterShape(BasicShapes.Ellipse);

Create Hidden Stencils

Set the isVisible DiagramStencil constructor parameter to false to create hidden stencils. Hidden stencils are not shown in the Shapes panel, but their shapes can be used in the diagram. See the example below.

 DiagramStencil myStencil = new DiagramStencil("myInvisibleStencil",
     "My Invisible Stencil", false);
See Also