I have this code:

If e.Delta <> 0 Then
            If e.Delta <= 0 Then
                If PictureBox1.Width < 500 Then Exit Sub 'minimum 500?
                If PictureBox1.Width > 2000 Then Exit Sub 'maximum 2000?
            End If

            PictureBox1.Size = New System.Drawing.Size(PictureBox1.Width + e.Delta / 1, PictureBox1.Height + e.Delta / 1)
            PictureBox1.Location = New Point(Control.MousePosition.X - PictureBox1.Width / 2, Control.MousePosition.Y - PictureBox1.Height / 2)
        End If

which zooms the PictureBox to the center of the cursor location, but when I insert the picturebox to a panel, the image does not properly zoom in to the center of the image, instead to the edge of the panel.

How would I fix this?

2 Years
Discussion Span
Last Post by Reverend Jim

If you mean something like this...


Then I believe I can help. If you are still around and you haven't figure it out then let me know. I'm going to paste the code any way for other people to get a rough idea of whats happening behind the scenes.

Note: I think what your doing is resizing an actual picturebox, the picture box is inside a panel so the panel acts as a clipping area. What this code does is process the image in memory, and draws the centered zoomed image to the view picture box. The picturebox on the left is a visual representation of whats going on in memory.


I'm still using vb.net 2010 so I had to do a little fiddling but everything works just fine. I suppose I should upgrade (next system rebuild).

Edited by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.