Home : Annotations : Custom : Make your custom annotation cloneable
Q10217 - HOWTO: Make your custom annotation cloneable

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.

override object Clone()
    TriangleData data =
new TriangleData();
    data._fill = (
this._fill == null ? null : this._fill.Clone());
    return data;

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())
    End If

    Return data
End Function

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))
End Function

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.

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?


Tell us why you rated the content this way. (optional)
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2019. InstantASP Ltd. All Rights Reserved