I have created an application where the user scan an image.
The scanned image is shown in a picturebox with BackgroundImageTileMode = Stretch, and this picturebox is placed in a Panel with AutoScroll=true.
At a click on the image, the user can place labels on the image. I add them at runtime at the MouseUp position like this:
Private Sub picScannedImage_MouseUp(sender As Object, e As MouseEventArgs) Handles picScannedImage.MouseUp
Dim nNewLabel As New Label
With nNewLabel
.AutoSize = True
.Text = "aA"
.Location = New Point(e.X, e.Y - .Height)
End With
Me.picScannedImage.Controls.Add(nNewLabel)
nNewLabel.Location = New Point(e.X, e.Y - nNewLabel.Height)
_ListOfAllLabels.Add(nNewLabel) 'so that I know where the user clicked / where he wants the labels to be
End Sub
The user can later export the scanned image as a PDF, and I will put textfields where the user clicked. This way, the PDF will be editable.
Since the scanned image might be large, I give the user the option to zoom into in. At zooming in, I resize the picturebox. The panel will detect if the picturebox is too large to be entirely displayed, and it will show the scrollbars. The user can use the scrollbars to scroll the image.
When the user zooms in, I need to reposition the labels. Also, when the user now clicks somewhere, I need to add a new label. However, I need to take into account that image is zoomed and that the image is moved (because the image was scrolled). How could I calculate the label's position in this zoomed and scrolled image?
I would also like to ask how I could conviniently calculate the "real" click position (= where the user would have clicked if the image wasn't zoomed and wasn't scrolled).
Thank you!