Hi all,

I have a form that pops up and displays pictures. I've some code that enables zooming in/out of the image. Code works fine:
Code:
Sub ImageCenter3()
        img.Left = (Me.ScaleWidth - img.Width) / 2
        img.Top = (Me.ScaleHeight - img.Height) / 2
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim x As Double
        'me.KeyPreview = True' needs to be on for this event to fire on all presses.
        x = 300 'zoom increment
        If KeyCode = 107 Or KeyCode = 187 Then ' 43 "+" keys -> Zoom in
            img.Stretch = True
            img.Width = img.Width + x
            img.Height = img.Height + x
            Call ImageCenter3
        ElseIf KeyCode = 109 Or KeyCode = 189 Then ' 45 "-" keys -> Zoom out
            img.Stretch = True
            img.Width = img.Width - x
            img.Height = img.Height - x
            Call ImageCenter3
        ElseIf KeyCode = 48 Or KeyCode = 96 Then ' "0" key -> Fit to window
            Call Form_Resize
        ElseIf KeyCode = 49 Or KeyCode = 97 Then ' "1" key -> set to 100%
            img.Stretch = False
            Call ImageCenter3
        ElseIf KeyCode > 49 And KeyCode < 59 Then  ' 2,3,4,5,6,7,8,9 ,factor of *100% zoom
            img.Stretch = True
            x = KeyCode - 48
            img.Width = imgX * x
            img.Height = imgY * x
            Call ImageCenter3
        ElseIf KeyCode > 97 And KeyCode < 106 Then  ' ------- " -------
            img.Stretch = True
            x = KeyCode - 96
            img.Width = imgX * x
            img.Height = imgY * x
            Call ImageCenter3
        End If
        
End Sub
My challenge:
The code above will allways reset the position of the image and zoom in/out from the center of the image (because of the "/ 2" operation in ImageCenter3().
I also have code that enables panning the image.
Q: How can I enable zooming in/out based on the center of what is visible on the form (which might not be the center of the image, if I have panned...)?