When creating a custom annotation, the ability to clone the annotation can be important. This article will step through the process of making your custom annotation cloneable.
The first step is to override the Clone method in your annotation data class. The trick is to create a new instance of your data class and pass it into the CloneBaseData method so the AnnotationData properties will be cloned. After that, it’s simply a matter of cloning your custom properties and returning the object. Here is an example from our TriangleData class found in the "Annotation Demo" source.
public override object Clone()
TriangleData data = new TriangleData();
data._fill = (this._fill == null ? null : this._fill.Clone());
Public Overrides Function Clone() As Object
Dim data As TriangleData = New TriangleData
If Me._fill Is Nothing Then
data._fill = (Nothing)
data._fill = (Me._fill.Clone())
The next step is to override the Clone method in your annotation UI class. Here you simply create a new instance of your annotation and pass in a clone of your annotation data class. If you add any custom properties to the UI that are not in the data class, those will have to be cloned here as well.
public override AnnotationUI Clone()
return new TriangleAnnotation((TriangleData)this._data.Clone());
Public Overrides Function Clone() As AnnotationUI
Return New TriangleAnnotation(CType(Me._data.Clone(), TriangleData))
That is all it takes to make your custom annotation cloneable. A full custom annotation example can be found in the "Annotation Demo" source code provided in the DotImage SDK download.