Search

Atalasoft Knowledge Base

HOWTO: Add an Annotation Programmatically in AnnotateViewer (Windows Forms Controls)

Administrator
DotImage

Given an AnnotateViewer, a location and a size, this method will place a new RectangleAnnotation on the given viewer. It is necessary to ensure that there is at least one layer to start with. This code places the annotation on the viewer’s current layer. If there is no current layer, it defaults it to layer 0.

C#

private void AddNewRectangleAnnotation(AnnotateViewer viewer, PointF location, SizeF size)
{
	// no layers? make one
    if (viewer.Annotations.Layers.Count == 0) 
    {
    	viewer.Annotations.Layers.Add(new LayerAnnotation());
    }

    // no current layer?  set it to the 0th
    if (viewer.Annotations.CurrentLayer == null) 
    {
        viewer.Annotations.CurrentLayer = viewer.Annotations.Layers[0];
    }
 
    // make the annot
    RectangleAnnotation annot = new RectangleAnnotation(new AnnotationBrush(Color.Plum), new AnnotationPen(Color.Black));
    annot.Location = location;
    annot.Size = size;
 
    // add it to viewer
    viewer.Annotations.CurrentLayer.Items.Add(annot);
}

Original Article:
Q10167 - HOWTO: Add an Annotation Programmatically in Windows Forms AnnotateViewer

Details
Last Modified: 2 Weeks Ago
Last Modified By: Administrator
Type: HOWTO
Article not rated yet.
Article has been viewed 13 times.
Options
Also In This Category