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
annotation should be visible, when I get the position on the viewer
Moderator: Alex
-
- Posts: 40
- Joined: Thu Apr 09, 2015 7:57 am
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: annotation should be visible, when I get the position on the viewer
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
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
-
- Posts: 40
- Joined: Thu Apr 09, 2015 7:57 am
Re: annotation should be visible, when I get the position on the viewer
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
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
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: annotation should be visible, when I get the position on the viewer
Could you send me a small working project which demonstrates your problem?
Best regards, Alexander
Best regards, Alexander
-
- Posts: 40
- Joined: Thu Apr 09, 2015 7:57 am
Re: annotation should be visible, when I get the position on the viewer
Hella Alex!
Can i send you Images?
lg GH
Can i send you Images?
lg GH
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: annotation should be visible, when I get the position on the viewer
Yes, please send me screenshots.
Best regards, Alexander
Best regards, Alexander
-
- Posts: 40
- Joined: Thu Apr 09, 2015 7:57 am
Re: annotation should be visible, when I get the position on the viewer
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]
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]
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: annotation should be visible, when I get the position on the viewer
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:
Please let me know if you will have any question or problem.
Best regards, Alexander
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
Best regards, Alexander
-
- Posts: 40
- Joined: Thu Apr 09, 2015 7:57 am
Re: annotation should be visible, when I get the position on the viewer
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
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
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: annotation should be visible, when I get the position on the viewer
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.
Best regards, Alexander
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