how to maintain the location of a picturebox in the panel

411 views Asked by At

i want to maintain the location of picturebox2 which is inside a panel. in my case, the image looks like this.. https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ8SUu7ZXBJVXrhic-Xou9OsW4h7QDd8yH5xhYtV3DlnJ0Q1UVJiw (there's a map /picturebox1/ and the color green locator or pointer is another picturebox /picturebox2/)

is it possible to zoom in and zoom out the image without losing the right coordinates? Because i want to maintain the location of the locator(picturebox2) in the map (picturebox1)

so far, i can now zoom in and zoom out the image in the scrollable panel using trackbar. but my only problem is that, the picturebox2 (another image above the picturebox1) needs to move its location as picturebox1 is zooming.

Public ClassForm1
Private img original As Image
Private m_PanStartPoint As New Point
Private n_PanStartPoint As New Point

Private Sub Form1_Load(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load
imgoriginal = Image.FromFile("C:\New Folder\picture1.jpg")
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
zoomSlider.Minimum = 1
zoomSlider.Maximum = 5
zoomSlider.SmallChange = 1
zoomSlider.LargeChange = 1
zoomSlider.UseWaitCursor = False
Me.DoubleBuffered = True
        Panel1.AutoScroll = True
        PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
        PictureBox1.Parent = PictureBox1
        PictureBox2.Parent = PictureBox1
        PictureBox1.BackColor = Color.Transparent
Dim mstream As NewSystem.IO.MemoryStream()
    PictureBox1.Image = Image.FromStream(mstream)
    PictureBox2.Location = NewSystem.Drawing.Point(100, 100)
End Sub

Public Function pictureboxzoom(ByValimgAsImage, ByVal size AsSize) AsImage
Dim bm As Bitmap = New Bitmap(img, Convert.ToInt32(img.Width * size.Width),     Convert.ToInt32(img.Height * size.Height))
Dim grap As Graphics = Graphics.FromImage(bm)
grap.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
Return bm
    End Function

Private Sub zoomSlider_Scroll(ByVal sender AsSystem.Object, ByVal e     AsSystem.EventArgs) Handles zoomSlider.Scroll
If zoomSlider.Value> 0 Then
            PictureBox1.Image = Nothing
            PictureBox1.Image = pictureboxzoom(imgoriginal, New     Size(zoomSlider.Value, zoomSlider.Value))
End If
End Sub

Private Sub PictureBox1_MouseDown(ByVal sender AsObject, ByVal e AsSystem.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
m_PanStartPoint = NewPoint(e.X, e.Y)
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender AsObject, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then

Dim DeltaX As Integer = (m_PanStartPoint.X - e.X)
Dim DeltaY As Integer = (m_PanStartPoint.Y - e.Y)
Panel1.AutoScrollPosition = _
New Drawing.Point((DeltaX - Panel1.AutoScrollPosition.X), _
                    (DeltaY - Panel1.AutoScrollPosition.Y))
            Button1.Location = New System.Drawing.Point(0, 0)
End If
End Sub
End Class
0

There are 0 answers