Annotation view in WinForms
In This Topic
The
AnnotationView class is always created on the base of
AnnotationData class and defines the annotation's visual appearance and the way the user may interact with annotation.
Link between classes derived from
AnnotationData and
AnnotationView is registered using the
AnnotationViewFactory.RegisterViewForAnnotationData method.
As in the case with classes derived from
AnnotationData class, the classes derived from
AnnotationView class are divided into 3 types:
AnnotationView class contains the
AnnotationView.Data property, which allows to get reference to a linked instance
AnnotationData class. Also
AnnotationView class contains a set of properties similar to the properties of
AnnotationData class, which allow to relay annotation's properties through
AnnotationView.
Here is C#/VB.NET code that shows how to create an instance of view for
EllipseAnnotationData annotation:
public static Vintasoft.Imaging.Annotation.UI.AnnotationView CreateViewForEllipseAnnotationData(
Vintasoft.Imaging.Annotation.EllipseAnnotationData ellipseAnnotation)
{
return new Vintasoft.Imaging.Annotation.UI.EllipseAnnotationView(ellipseAnnotation);
}
Public Shared Function CreateViewForEllipseAnnotationData(ellipseAnnotation As Vintasoft.Imaging.Annotation.EllipseAnnotationData) As Vintasoft.Imaging.Annotation.UI.AnnotationView
Return New Vintasoft.Imaging.Annotation.UI.EllipseAnnotationView(ellipseAnnotation)
End Function
Annotation bounding rectangles
The visual appearance of annotation has several bounding rectangle types. The following types are used for solving various tasks related to correct drawing and interaction with annotation:
- "Bounding Box" - defines the rectangle aligned by axises, which encloses annotation.That rectangle is defined only by AnnotationView.Location, AnnotationView.Size and AnnotationView.Rotation properties of annotation, and may be used as a basis for "Drawing Box" calculating. For getting the rectangle is necessary to call AnnotationView.GetBoundingBox method.
- "Author Bounding Box" - defines the rectangle aligned by axises, which by-turn defines the annotation areaduring annotation transformation, as well as is used for annotation selection in annotation viewer. In most cases "Author Bounding Box" conforms to "Bounding Box" area of annotation. For getting the rectangle is necessary to call AnnotationView.GetAuthorBoundingBox method. This method is a virtual one, that's why it's possible to override it in classes derived from AnnotationView class.
- "Drawing Box" - defines the rectangle aligned by axises, which fully encloses the entire visual part of annotation,but nothing more. "Drawing Box" can be larger than "Bounding Box" because of additional visual elements of annotation, like annotation shadow, caption with value of annotation length, smoothinh of interpolated lines, etc.
Focus annotation in WinForms annotation viewer
Every annotation may receive focus in the image viewer. When an annotation is focused there appears a selection rectangle around it, which can be transformed (scaled, mirrored, rotated) and the annotation will be transformed in proportion to the selection rectangle.
The views for annotations, which are based on a set of points, in addition, may be transformed using points. When annotation is selected - all of its points become selected, the user may change the location of each point using dragging.
Also the views for annotations, which are based on a set of points, support composite selection mode, which allows to transform annotation both using selection rectangle and using points.
The selection/transformation mode of annotation, which are based on a set of points, may be changed using
LineAnnotationViewBase.GripMode property.
Build and transform annotation in WinForms annotation viewer
AnnotationView.Builder property defines the interactive controller, which is used for annotation building.
AnnotationView.Transformer property defines the interactive controller, which is used for annotation transformation.
Also
AnnotationView class has
AnnotationView.InteractionController property which defines the currently used interactive controller.
Detailed information about building and transformation of annotation can be found in article:
Building and transformation of annotations in WinForms.
Monitor the annotation state
AnnotationView class provides events, which allow to monitor the annotation state:
- AnnotationView.Drawing - occurs before annotation is drawing.
- AnnotationView.Drawn - occurs after annotation is drawn.
- AnnotationView.MouseDown - occurs when the mouse pointer is over the annotation and the mouse button is pressed.
- AnnotationView.MouseUp - occurs when the mouse pointer is over the annotation and the mouse button is released.
- AnnotationView.MouseEnter - occurs when the mouse pointer enters the annotation.
- AnnotationView.MouseMove - occurs when the mouse pointer rests on the annotation.
- AnnotationView.MouseLeave - occurs when the mouse pointer leaves the annotation.
- AnnotationView.MouseWheel - occurs when the mouse wheel moves while the annotation has focus.
- AnnotationView.Click - occurs when the annotation is clicked.
- AnnotationView.DoubleClick - occurs when the annotation is double-clicked.
- AnnotationView.StateChanged - occurs when the state of annotation is changed, e.g. arrived PropertyChanged event from data annotation object.
Annotation collection
The
AnnotationViewCollection class is always created on the base of
AnnotationDataCollection class and represents a collection of annotation's views, which are linked with annotation data from
AnnotationDataCollection.
The
AnnotationViewCollection class makes changes synchronously in its collection and in linked
AnnotationDataCollection.
The
AnnotationViewCollection class provides the ability to add, remove, reorder, resort elements, transform to
AnnotationView elements array, access to
AnnotationDataCollection. Also
AnnotationViewCollection class allows to:
- search AnnotationView element linked with specified instance of AnnotationData
- render all views from a collection on specified System.Windows.Media.DrawingContext object
- render all views from a collection on specified VintasoftImage.