Page 1 of 2

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

Posted: Tue Jul 28, 2015 12:24 pm
by GHWels
Hello Alex!

I want to create a

Dim Data As TextAnnotationData = New TextAnnotationData()
Data.AutoSize = True
.
.

The annotation should be visible, when I pick the textposition on the viewer with the mouse.

lg GH

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

Posted: Wed Jul 29, 2015 10:17 am
by Alex
Hello Gunther,

I am not sure I have understood your needs. Do you want to draw annotation on image when user clicked on annotation viewer?

Best regards, Alexander

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

Posted: Wed Jul 29, 2015 12:14 pm
by GHWels
Hallo Alex!

No I want do create a text and then I want to see the text, when i place it at the right Position in the viewer.

lg GH

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

Posted: Wed Jul 29, 2015 4:37 pm
by Alex
Could you send me a small working project which demonstrates your problem?

Best regards, Alexander

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

Posted: Thu Jul 30, 2015 8:31 am
by GHWels
Hella Alex!

Can i send you Images?

lg GH

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

Posted: Thu Jul 30, 2015 9:20 am
by Alex
Yes, please send me screenshots.

Best regards, Alexander

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

Posted: Thu Jul 30, 2015 4:38 pm
by GHWels
Hello Alex!

1.) I create the text "Herbsthofer"
2.) The text will be created at the Poistion of the mousepointer, when i enter the Viewer
3.) Then the annotion will be placed where I the mousebutton.

that it.

lg GH

[img]C:\Users\gh\Pictures\H1.png[/img]
[img]C:\Users\gh\Pictures\H2.png[/img]
[img]C:\Users\gh\Pictures\H3.png[/img]
[img]C:\Users\gh\Pictures\H4.png[/img]

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

Posted: Thu Jul 30, 2015 6:22 pm
by Alex
Hello Gunther,

For doing your task you need:
1. Subscribe to the MouseClick event of annotation viewer when you need create text annotation
2. Create text annotation and add it to an image in annotation viewer when mouse is clicked on viewer

Here is code snippet that shows how to do your task:

Code: Select all

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.

Best regards, Alexander

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

Posted: Thu Jul 30, 2015 7:22 pm
by GHWels
Hello Alex!

Nearly perfekt, but I wanted to see the text bevor at the position of the mousepointespeek , while I move the mousepointer.

But I think I can live with the solution.

Thank you very much.

lg GH

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

Posted: Fri Jul 31, 2015 11:29 am
by Alex
Hello Gunther,

I updated code snippet and now I hope it fully suits your needs.

Here is an example that creates text annotation and hovers the annotation over image until mouse button is not pressed. Example uses mouse move and mouse click events.

Code: Select all

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