annotation should be visible, when I get the position on the viewer

Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.

Moderator: Alex

Alex
Site Admin
Posts: 1474
Joined: Thu Jul 10, 2008 2:21 pm

Re: annotation should be visible, when I get the position on the viewer

Post by Alex » Fri Jul 31, 2015 11:53 am

You can do your task by 2 ways:
  • Using mouse events. In this case you need subscribe to necessary events and define logic in events.
  • Using annotation builder. In this case you need create annotation builder - class that defines annotation building logic, and specify that annotation must be built using custom annotation builder.
Here is an example that shows how to do your task using custom annotation builder:

Code: Select all

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    ' create text annotation data
    Dim textAnnoData As TextAnnotationData = New TextAnnotationData()
    ' specify that annotation size must be calculated automatically depending on text content
    textAnnoData.AutoSize = True
    ' specify annotation text
    textAnnoData.Text = "Hallo"
    ' specify annotation location
    textAnnoData.Location = New PointF(-1000, -1000)

    ' create text annotation view
    Dim textAnnoView As TextAnnotationView = New TextAnnotationView(textAnnoData)
    ' define custom builder for text annotation view
    textAnnoView.Builder = New MyTextAnnotationBuilder(textAnnoView)

    ' add annotation view to the first image in annotation viewer
    annotationViewer1.AddAndBuildAnnotation(textAnnoView)
End Sub

''' <summary>
''' Custom builder of text annotation.
''' </summary>
Public Class MyTextAnnotationBuilder
    Inherits RectangularAnnotationBuilder

    ' annotation width before transform
    Dim _widthBeforeTransform As Double
    ' annotation height before transform
    Dim _heightBeforeTransform As Double



    ''' <summary>
    ''' Initializes a new instance of the <see cref="MyTextAnnotationBuilder"/> class.
    ''' </summary>
    ''' <param name="annotation">The annotation.</param>
    Public Sub New(ByVal annotation As IRectangularInteractiveObject)
        MyBase.new(annotation)

        ' clear interaction areas of annotation
        InteractionAreaList.Clear()
        ' add new interaction area that has size equal to viewer size and interacts when mouse is hovered or moved over viewer
        InteractionAreaList.Add(New ImageViewerArea(InteractionAreaType.Hover Or InteractionAreaType.Movable))
    End Sub



    ''' <summary>
    ''' Performs the interaction with annotation.
    ''' </summary>
    Protected Overrides Sub PerformInteraction(args As Vintasoft.Imaging.UI.VisualTools.UserInteraction.InteractionEventArgs)
        Dim x0 As Double
        Dim y0 As Double
        Dim x1 As Double
        Dim y1 As Double

        ' if first user interaction with interaction area occurs
        If args.Action = InteractionAreaAction.Begin Then
            ' get bounding box of annotation
            InteractiveObject.GetRectangle(x0, y0, x1, y1)
            ' save annotation width and height
            _widthBeforeTransform = x1 - x0
            _heightBeforeTransform = y1 - y0

            ' if user moved mouse over interaction area
        ElseIf args.Action = InteractionAreaAction.Move Then
            ' calculate left-top point of annotation
            x0 = args.Location.X
            y0 = args.Location.Y
            ' calculate right-bottom point of annotation
            x1 = x0 + _widthBeforeTransform
            y1 = y0 + _heightBeforeTransform
            ' set bounding box of annotation
            InteractiveObject.SetRectangle(x0, y0, x1, y1)
            ' specify that interatcion occurs
            args.InteractionOccured(True)

            ' if user clicked on interaction area
        ElseIf args.Action = InteractionAreaAction.Click Then
            ' specify that interatcion is finished
            args.InteractionFinished = True

        End If
    End Sub

End Class
Best regards, Alexander

GHWels
Posts: 32
Joined: Thu Apr 09, 2015 7:57 am

Re: annotation should be visible, when I get the position on the viewer

Post by GHWels » Fri Jul 31, 2015 5:24 pm

Hello Alex!

Thank you very much. Perfekt

lg GH
Best regards, GHWels

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest