VintaSoft Annotation .NET Plug-in Discussions
Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.
Board index < VintaSoft Imaging < VintaSoft Annotation .NET Plug-in Discussions
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' subscribe to the mouse click event of annotation viewer
AddHandler annotationViewer1.MouseClick, AddressOf annotationViewer1_OnMouseClicked
End Sub
''' <summary>
''' Mouse clicked on annotation viewer.
''' </summary>
Private Sub annotationViewer1_OnMouseClicked(ByVal sender As Object, ByVal e As MouseEventArgs)
' unsubscribe to the mouse click event of annotation viewer
RemoveHandler annotationViewer1.MouseClick, AddressOf annotationViewer1_OnMouseClicked
' convert mouse location from viewer space to the image space
Dim mouseLocationOnImage As PointF = annotationViewer1.PointToImage(e.Location)
' get resolution of first image
Dim imageResolution As Resolution = annotationViewer1.Images(0).Resolution
' convert mouse location from image space to annotations space
Dim mouseLocationInAnnoSpace As PointF = New PointF(mouseLocationOnImage.X / imageResolution.Horizontal * 96, mouseLocationOnImage.Y / imageResolution.Vertical * 96)
' create text annotation data
Dim data As TextAnnotationData = New TextAnnotationData()
' specify that annotation size must be calculated automatically depending on text content
data.AutoSize = True
' specify annotation text
data.Text = "Hallo"
' specify annotation location
data.Location = New PointF(mouseLocationInAnnoSpace.X + data.Size.Width / 2, mouseLocationInAnnoSpace.Y + data.Size.Height / 2)
' create text annotation view
Dim view As TextAnnotationView = New TextAnnotationView(data)
' add annotation view to the first image in annotation viewer
annotationViewer1.AnnotationViewController(0).Add(view)
End Sub
Please let me know if you will have any question or problem.Dim _textAnnoData As TextAnnotationData = Nothing
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' subscribe to the mouse move event of annotation viewer
AddHandler annotationViewer1.MouseMove, AddressOf annotationViewer1_OnMouseMove
' subscribe to the mouse click event of annotation viewer
AddHandler annotationViewer1.MouseClick, AddressOf annotationViewer1_OnMouseClicked
End Sub
''' <summary>
''' Mouse is moved over annotation viewer.
''' </summary>
Private Sub annotationViewer1_OnMouseMove(sender As Object, e As MouseEventArgs)
' add the text annotation to an image in viewer
AddTextAnnotationToImage(e.Location)
End Sub
''' <summary>
''' Mouse clicked on annotation viewer.
''' </summary>
Private Sub annotationViewer1_OnMouseClicked(ByVal sender As Object, ByVal e As MouseEventArgs)
' unsubscribe to the mouse move event of annotation viewer
RemoveHandler annotationViewer1.MouseMove, AddressOf annotationViewer1_OnMouseMove
' unsubscribe to the mouse click event of annotation viewer
RemoveHandler annotationViewer1.MouseClick, AddressOf annotationViewer1_OnMouseClicked
' add text annotation to an image in viewer
AddTextAnnotationToImage(e.Location)
_textAnnoData = Nothing
End Sub
''' <summary>
''' Adds text annotation to an image in viewer.
''' </summary>
''' <param name="mouseLocationOnViewer">The mouse location on viewer.</param>
Private Sub AddTextAnnotationToImage(ByVal mouseLocationOnViewer As Point)
' convert mouse location from viewer space to the image space
Dim mouseLocationOnImage As PointF = annotationViewer1.PointToImage(mouseLocationOnViewer)
' get resolution of first image
Dim imageResolution As Resolution = annotationViewer1.Images(0).Resolution
' convert mouse location from image space to annotations space
Dim mouseLocationInAnnoSpace As PointF = New PointF(mouseLocationOnImage.X / imageResolution.Horizontal * 96, mouseLocationOnImage.Y / imageResolution.Vertical * 96)
' if text annotation is NOT created yet
If _textAnnoData Is Nothing Then
' create text annotation data
_textAnnoData = 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(mouseLocationInAnnoSpace.X + _textAnnoData.Size.Width / 2, mouseLocationInAnnoSpace.Y + _textAnnoData.Size.Height / 2)
' create text annotation view
Dim textAnnoView As TextAnnotationView = New TextAnnotationView(_textAnnoData)
' add annotation view to the first image in annotation viewer
annotationViewer1.AnnotationViewController(0).Add(textAnnoView)
' if text annotation is created already
Else
' update annotation location
_textAnnoData.Location = New PointF(mouseLocationInAnnoSpace.X + _textAnnoData.Size.Width / 2, mouseLocationInAnnoSpace.Y + _textAnnoData.Size.Height / 2)
End If
End Sub
Best regards, Alexander