Skip to main content

How to: Create a Shape

  • 3 minutes to read

This topic describes how to create a shape and change its form, size, and rotation angle.

Create a Shape

The example below shows how to use the ShapeCollection.AddShape method overloads to insert shapes into a worksheet.

Spreadsheet_AddMultipleShapes

// Set the measurement unit to Inches.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch;

// Insert a shape at the specified position in a worksheet.
Shape shape1 = worksheet.Shapes.AddShape(ShapeGeometryPreset.RectangularCallout, 0.68f, 0.22f, 2f, 1.25f);

// Insert a shape so that its top left corner is in the specified cell.
Shape shape2 = worksheet.Shapes.AddShape(ShapeGeometryPreset.RoundedRectangularCallout, worksheet.Cells["F2"], 2f, 1.25f);

// Insert a shape that fits into the specified cell range.
Shape shape3 = worksheet.Shapes.AddShape(ShapeGeometryPreset.OvalCallout, worksheet["J2:L7"]);

Change a Shape’s Location

Use the following API to define a shape’s location in a worksheet:

Member Description
FloatingObject.Move Moves the shape by the specified offsets.
FloatingObject.Top Specifies the distance between the top edge of the worksheet and the shape’s top left corner.
FloatingObject.Left Specifies the distance between the left edge of the worksheet and the shape’s top left corner.
FloatingObject.TopLeftCell Specifies the cell where the shape’s top left corner is located.
FloatingObject.BottomRightCell Specifies the cell where the shape’s bottom right corner is located.
FloatingObject.OffsetX Specifies the distance between the shape’s top left corner and the left edge of the TopLeftCell cell.
FloatingObject.OffsetY Specifies the distance between the shape’s top left corner and the top edge of the TopLeftCell cell.
shape2.TopLeftCell = worksheet.Cells["F4"];
shape2.BottomRightCell = worksheet.Cells["H9"];

Spreadsheet_Shape_Change_Location

Resize and Rotate a Shape

Use the following properties to rotate and resize a shape:

Property Description
Shape.Rotation Specifies the shape’s rotation angle.
FloatingObject.Width Specifies the shape’s width.
FloatingObject.Height Specifies the shape’s height.
shape3.Rotation = 45;
shape3.Width = 2.2f;
shape3.Height = 1.5f;

Spreadsheet_Shape_RotateResize

Change a Shape’s Form

Use the ShapeGeometry.Preset property to change a shape’s geometry type. The example below shows how to transform a rectangular callout into a cloud callout.

Spreadsheet_Shape_ChangePreset

shape1.ShapeGeometry.Preset = ShapeGeometryPreset.CloudCallout;
See Also