VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction Namespace / RectangularTextAnnotationTransformer Class
Members Example



In This Topic
    RectangularTextAnnotationTransformer Class
    In This Topic
    Interaction controller that transforms rectangular text annotation.
    Object Model
    RectangularTextAnnotationTransformer ClassInteractionArea ClassRectangularAnnotationTransformer ClassTextObjectTextBoxTransformer Class
    Syntax
    Example
    This example shows how to set custom font, location and size of the text box of the text annotations:
    Public Class MainForm
        Inherits System.Windows.Forms.Form
        ''' <summary>
        ''' Main annotation viewer.
        ''' </summary>
        Private _viewer As Vintasoft.Imaging.Annotation.UI.AnnotationViewer
                
        ' ...
                
        Public Sub New()
            ' ...
                
            ' subscribe to the FocusedAnnotationViewChanged event of viewer
                
                ' ...
            AddHandler _viewer.FocusedAnnotationViewChanged, New System.EventHandler(Of Vintasoft.Imaging.Annotation.UI.AnnotationViewChangedEventArgs)(AddressOf _viewer_FocusedAnnotationViewChanged)
        End Sub
                
        ''' <summary>
        ''' Handler of the FocusedAnnotationViewChanged event.
        ''' </summary>
        Private Sub _viewer_FocusedAnnotationViewChanged(sender As Object, e As Vintasoft.Imaging.Annotation.UI.AnnotationViewChangedEventArgs)
            ' text transformer of old annotation
            Dim textTransformer As Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.RectangularTextAnnotationTransformer = Nothing
            If TypeOf e.OldValue Is Vintasoft.Imaging.Annotation.UI.TextAnnotationView Then
                textTransformer = DirectCast(e.OldValue, Vintasoft.Imaging.Annotation.UI.TextAnnotationView).TextTransformer
            ElseIf TypeOf e.OldValue Is Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView Then
                textTransformer = DirectCast(e.OldValue, Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView).TextTransformer
            End If
                
            If textTransformer IsNot Nothing Then
                ' unsubscribe from the TextBoxUpdated event of viewer
                RemoveHandler textTransformer.TextBoxTransformer.TextBoxUpdated, New System.EventHandler(Of Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs)(AddressOf textTransformer_TextBoxUpdated)
            End If
                
            ' text transformer of new annotation
            textTransformer = Nothing
            If TypeOf e.NewValue Is Vintasoft.Imaging.Annotation.UI.TextAnnotationView Then
                textTransformer = DirectCast(e.NewValue, Vintasoft.Imaging.Annotation.UI.TextAnnotationView).TextTransformer
            ElseIf TypeOf e.NewValue Is Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView Then
                textTransformer = DirectCast(e.NewValue, Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView).TextTransformer
            End If
                
            If textTransformer IsNot Nothing Then
                ' set new font of the text box
                textTransformer.TextBox.Font = New System.Drawing.Font("Arial", 20, System.Drawing.FontStyle.Bold)
                ' set text box location and size calculation mode to manual
                textTransformer.AutomaticallyCalculateTextBoxLocationAndSize = False
                ' subscribe to the TextBoxUpdated event of viewer
                AddHandler textTransformer.TextBoxTransformer.TextBoxUpdated, New System.EventHandler(Of Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs)(AddressOf textTransformer_TextBoxUpdated)
            End If
        End Sub
                
        ''' <summary>
        ''' Handler of the TextBoxUpdated event.
        ''' Location and size of the text box are setting to such values that text box matches
        ''' the visible part of the text annotation.
        ''' </summary>
        Private Sub textTransformer_TextBoxUpdated(sender As Object, e As Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs)
            ' get the text annotation
            Dim textAnnotation As Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.IRectangularTextAnnotation = DirectCast(e.TextObject, Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.IRectangularTextAnnotation)
            ' get bounding box of the annotation in the coordinate system of the viewer
            Dim annotationBoundingBox As System.Drawing.RectangleF = Vintasoft.Imaging.Utils.GraphicsUtils.TransformRect(textAnnotation.GetBoundingBox(), textAnnotation.GetPointTransform(_viewer))
            ' intersect with the visible area of the viewer
            Dim newBounds As System.Drawing.Rectangle = System.Drawing.Rectangle.Intersect(System.Drawing.Rectangle.Round(annotationBoundingBox), _viewer.ClientRectangle)
            ' set new bounds
            e.TextBox.Bounds = newBounds
        End Sub
    End Class
    public class MainForm : System.Windows.Forms.Form
    {
        /// <summary>
        /// Main annotation viewer.
        /// </summary>
        Vintasoft.Imaging.Annotation.UI.AnnotationViewer _viewer;
                
        // ...
                
        public MainForm()
        {
            // ...
                
            // subscribe to the FocusedAnnotationViewChanged event of viewer
            _viewer.FocusedAnnotationViewChanged += 
                new System.EventHandler<Vintasoft.Imaging.Annotation.UI.AnnotationViewChangedEventArgs>(_viewer_FocusedAnnotationViewChanged);
                
            // ...
        }
                
        /// <summary>
        /// Handler of the FocusedAnnotationViewChanged event.
        /// </summary>
        void _viewer_FocusedAnnotationViewChanged(object sender, Vintasoft.Imaging.Annotation.UI.AnnotationViewChangedEventArgs e)
        {
            // text transformer of old annotation
            Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.RectangularTextAnnotationTransformer textTransformer = null;
            if (e.OldValue is Vintasoft.Imaging.Annotation.UI.TextAnnotationView)
            {
                textTransformer = ((Vintasoft.Imaging.Annotation.UI.TextAnnotationView)e.OldValue).TextTransformer;
            }
            else if (e.OldValue is Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView)
            {
                textTransformer = ((Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView)e.OldValue).TextTransformer;
            }
                
            if (textTransformer != null)
            {
                // unsubscribe from the TextBoxUpdated event of viewer
                textTransformer.TextBoxTransformer.TextBoxUpdated -= 
                    new System.EventHandler<Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs>(textTransformer_TextBoxUpdated);
            }
                
            // text transformer of new annotation
            textTransformer = null;
            if (e.NewValue is Vintasoft.Imaging.Annotation.UI.TextAnnotationView)
            {
                textTransformer = ((Vintasoft.Imaging.Annotation.UI.TextAnnotationView)e.NewValue).TextTransformer;
            }
            else if (e.NewValue is Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView)
            {
                textTransformer = ((Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView)e.NewValue).TextTransformer;
            }
                
            if (textTransformer != null)
            {
                // set new font of the text box
                textTransformer.TextBox.Font = new System.Drawing.Font(
                    "Arial", 20, System.Drawing.FontStyle.Bold);
                // set text box location and size calculation mode to manual
                textTransformer.AutomaticallyCalculateTextBoxLocationAndSize = false;
                // subscribe to the TextBoxUpdated event of viewer
                textTransformer.TextBoxTransformer.TextBoxUpdated += 
                    new System.EventHandler<Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs>(textTransformer_TextBoxUpdated);
            }
        }
                
        /// <summary>
        /// Handler of the TextBoxUpdated event.
        /// Location and size of the text box are setting to such values that text box matches
        /// the visible part of the text annotation.
        /// </summary>
        void textTransformer_TextBoxUpdated(object sender, Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs e)
        {
            // get the text annotation
            Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.IRectangularTextAnnotation textAnnotation = 
                (Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.IRectangularTextAnnotation)e.TextObject;
            // get bounding box of the annotation in the coordinate system of the viewer
            System.Drawing.RectangleF annotationBoundingBox = Vintasoft.Imaging.Utils.GraphicsUtils.TransformRect(
                textAnnotation.GetBoundingBox(), textAnnotation.GetPointTransform(_viewer));
            // intersect with the visible area of the viewer
            System.Drawing.Rectangle newBounds = System.Drawing.Rectangle.Intersect(
                System.Drawing.Rectangle.Round(annotationBoundingBox), _viewer.ClientRectangle);
            // set new bounds
            e.TextBox.Bounds = newBounds;
        }
    }
    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.UI.VisualTools.UserInteraction.CompositeInteractionController
          Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.RectangularTextAnnotationTransformer

    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also