NShape Reference
CopyFrom Method

<< Click to Display Table of Contents >>

Navigation:  Class Reference > Namespace Dataweb.NShape > Shape Class >

NShape Reference
CopyFrom Method

Previous pageReturn to chapter overviewNext page

Copies property values from the source shape.


public abstract void CopyFrom(Shape source)


This method copies as many properties from the source shape to this shape as possible. If this shape and the source shape are of the same type, all properties will be copied. As a rule, all properties of the biggest common subtype are copied from the source to the target. This function is used to create shapes from shape templates, to copy and paste shapes within and between diagrams, creating preview shapes and when replacing shapes in diagrams.

Notes to implementers

Shapes have templated and regular properties. Templated properties are taken from the template, if they have not been made private explicitly. Regular properties are only copied once in the beginning. The CopyFrom method must copy both types of properties. Templated properties can be copied normally:

this.LineStyle = source.LineStyle;
if (source is IPlanarShape) {
  FillStyle = ((IPlanarShape)source).FillStyle;

The style property setter always checks whether the assigned style is identical to the style of the template and if so, sets the internal style field to null.

The framework uses this method to create new shapes based on a shape template. After creation of the new shape, its CopyFrom method is called to fetch the template shape's properties. When a shape is exchanged in the template, e.g. a circle shape is replaced by a rectangle shape, new shapes are created for all instances of the template, then they are copied from the new template shape and then they are copied from their predecessor to take over specific properties like private styles or caption texts.