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 FarPoint.Win.Spread.DrawingSpace.DrawingToolbar class allows you to bring up the shape toolbar at run-time. The SpreadWinDemo sample in the samples folder has a shapes form that shows you how to do this.
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:
- Add a shape in code using the AddShape method
- Remove a shape using the RemoveShape method
- Remove all the shapes using the ClearShapes method
- Get a shape using the GetShape method
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 should be detailed in the Assembly Reference. 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:
This constructs a basic rectangle shape with all default properties. Add the shape the active sheet.The example below shows an equally simple (but slightly fuller) set of code to accomplish the creation of a shape.
For more information on shapes, refer to the Spread Designer Guide.
Return to the overview of Customizing Drawing.
In this example, we create a shape, change some of the most used properties, and then to add it to the active sheet.
// 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 = "myRect1";
// 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);
' 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 = "myRect1"
' 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.
' This code will display the shape property dialog
' Dim f As New