Spread Windows Forms 12.0 Product Documentation
Working with Shapes in Code
Spread Windows Forms 12.0 Product Documentation > Developer's Guide > Customizing Sheet Interaction > Customizing Drawing > Working with Shapes in Code

There are several built-in shapes for you to use on a sheet. Each shape can be rotated and resized, and their ability to be rotated and resized by the end user can be constrained. When selected, the shape has resize handles with which you can adjust the size and a rotate handle with which you can rotate the shape. Colors, shadows, and transparency can be adjusted. Most users find it easy to create and place the shapes using Spread Designer. You may also create and place shapes using code.

The DynamicSize and DynamicMove properties specify how shapes are moved and resized when hiding or showing, resizing, or moving rows or columns that intersect with the shape or that appear before the shape (for example, resizing a column to the left or a row above the shape).

The following options are available:

Hiding columns and rows that contain a shape hides the shape as well.

The FarPoint.Win.Spread.DrawingSpace.DrawingToolbar class allows you to bring up the shape toolbar at run-time.

Besides working with shapes from Spread Designer, you can also add and remove shapes programmatically. You can perform the following work with shapes using the corresponding methods in the SheetView class:

To add a shape using code, refer to the DrawingSpace namespace and select the particular shape and define its properties using code. While there is much flexibility in setting up shapes, there are some limitations. These are listed in the Assembly Reference in the topics for the shape methods and classes. For example, for the LineShape class, the maximum thickness for a line is 64 pixels.

The simplest way to add a shape can be performed in one line of code, as shown in the following example:

fpSpread1.ActiveSheet.AddShape(New FarPoint.Win.Spread.DrawingSpace.RectangleShape())

This constructs a basic rectangle shape with default properties and adds the shape the active sheet. The following example creates a shape with custom settings.

For more information on shapes, refer to the Spread Designer Guide.

Example

This example creates a shape, changes some of the most used properties, and then adds it to the active sheet.

C#
Copy Code
  // Create a new shape.
   FarPoint.Win.Spread.DrawingSpace.RectangleShape rShape = new FarPoint.Win.Spread.DrawingSpace.RectangleShape();
   // Assign a name, overriding the unique default assigned name.
   // All shape names within a sheet must be unique.
   rShape.Name = "rShape1";
   // Assign a location at which to start the display of the shape.
   rShape.Top = 20;
   rShape.Left = 60;
   // Alternatively, you could set the Location property
   // with a Point object as in:
   // rShape.Location = new Point(20, 60);

   // Assign a custom fill color to the shape.
   rShape.BackColor = Color.Blue;
   // Assign a size to the shape.
   rShape.Width = 100;
   rShape.Height = 100;
   // Alternatively, you could set the Size property
   // with a Size object as in:
   // rShape.Size = new Size(100, 100);
   // Add the shape to the sheet so that it appears on that sheet.
   fpSpread1.ActiveSheet.AddShape(rShape);
   // This code will display the shape property dialog
   //FarPoint.Win.Spread.DrawingSpace.ShapeProps f = new FarPoint.Win.Spread.DrawingSpace.ShapeProps(fpSpread1);
   //f.Shape = fpSpread1.Sheets[0].DrawingContainer.GetShape("rShape1");
   //f.ShowDialog();
VB
Copy Code
  ' Create a shape.
  Dim rShape As New FarPoint.Win.Spread.DrawingSpace.RectangleShape()
  ' Assign a name, overriding the unique default assigned name.
  ' All shape names within a sheet must be unique.
  rShape.Name = "rShape1"
  ' Assign a location at which to start the display of the shape.
  rShape.Top = 20
  rShape.Left = 60
  ' Alternatively, you could set the Location property
  ' with a Point object as in:
  ' rShape.Location = New Point(20, 60)

  ' Assign a custom fill color to the shape.
  rShape.BackColor = Color.Blue
  ' Assign a size to the shape.
  rShape.Width = 100
  rShape.Height = 100
  ' Alternatively, you could set the Size property
  ' with a Size object as in:
  ' rShape.Size = New Size(100, 100)
  ' Add the shape to the sheet so that it appears on that sheet.
  fpSpread1.ActiveSheet.AddShape(rShape)
  ' This code will display the shape property dialog
  ' Dim f As New
  'FarPoint.Win.Spread.DrawingSpace.ShapeProps(fpSpread1)
  'f.Shape =
  'fpSpread1.Sheets(0).DrawingContainer.GetShape("rShape1")
  'f.ShowDialog()
See Also