Spread Windows Forms 14.0
Spread Windows Forms 14.0 Product Documentation / Developer's Guide / Customizing Drawing / Working with Shapes in Code
In This Topic
    Working with Shapes in Code
    In This Topic

    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. 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.

    Example

    This example constructs a basic rectangle shape with default properties and adds the shape the active sheet.

    C#
    Copy Code
    fpSpread1.ActiveSheet.AddShape(new FarPoint.Win.Spread.DrawingSpace.RectangleShape());
    
    VB
    Copy Code
    FpSpread1.ActiveSheet.AddShape(New FarPoint.Win.Spread.DrawingSpace.RectangleShape())
    

    Example

    The following example creates a shape with custom settings. 

    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);
    
    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)
    
    See Also