0

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.

enter image description here

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.

enter image description here

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!

tmighty
  • 10,734
  • 21
  • 104
  • 218
  • 2
    The answers in this post may help: [Translate Rectangle Position in Zoom Mode Picturebox](https://stackoverflow.com/q/53800328/3110834) – Reza Aghaei Dec 20 '20 at 01:12
  • 2
    Reza Aghaei's answer is probably more interesting there (still waiting for that property and related method to become public). I'm stubborn, still using *unmanaged* calculations. This one: [Zoom and translate an Image from the mouse location](https://stackoverflow.com/a/61964222/7444103) . See the `MouseOffset` Zoom mode and the corresponding `OffsetScaledRectangleOnMousePosition` method: it treats exactly rectangles offsets, to determine the rectangle relative offset and size when zooming in an out, considering delta and custom multiplier (to alter the zoom speed), with *tolerance*. – Jimi Dec 20 '20 at 02:03

0 Answers0