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

Glossary Item Box

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:

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:

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

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.

Example

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 = "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);
 
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 = "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)
 
  ' 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("rShape")
 
  'f.ShowDialog()
 

© 2002-2012 ComponentOne, a division of GrapeCity. All Rights Reserved.