Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Interface and Graphics (http://www.xtremevbtalk.com/-net-interface-and-graphics/)
-   -   move one picturebox inside another (http://www.xtremevbtalk.com/-net-interface-and-graphics/328900-move-picturebox-inside.html)

starmanMike 01-02-2018 09:43 AM

move one picturebox inside another
1 Attachment(s)
Hi, This is very similar to a question I raised earlier (VB6) for which you provided an excellent answer - but this time the coding is different (vb.net!) even though the problem is exactly the same.
I have one picbox (pic2) 'inside' another (pic1) and I need the user to be able to drag pic2 with the mouse. The image loaded into pic2 is always bigger than its container (pic1) which is why I need users to be able to drag it in order to see the Region Of Interest.
At the moment, the image loads into pic2 (full-size, OK so far!) and I have managed to drag it using code adapted from Passel's solution to my VB6 problem but if I drag it too far to the top left, everything in the bottom right disappears! I have attached a quick diagram which I hop will make things clearer.

passel 02-13-2018 10:13 PM

You probably should have posted an example of the code you're using so we could see it, and possibly identify a problem or suggest an alternative.
Given that you want to use a picture in a picture approach, here is a test case I tried.
I just added this to the example code I gave in the other post regarding color remapping, which is why it is using picturebox 3 and 4, rather than 1 and 2.
I stripped out the other code that dealt with the colormapping when posting here.
I just added a picturebox (picturebox3) and a much larger picturebox (picturebox4) to the form, and then tested with the following code.

    Private Sub Form1_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown

        'Create a bitmap and have picturebox4 reference it
        'Put picturebox4 in picturebox3 (locate at 0,0 to start)
        'Fill the picturebox4 bitmap with ellipses so we have something to see when we drag the picturebox around
        PictureBox4.Image = New Bitmap(PictureBox4.Width, PictureBox4.Height)
        PictureBox4.Parent = PictureBox3
        PictureBox4.Location = New Point(0, 0)
        Dim rand As New Random
        Dim w As Integer = PictureBox4.Width
        Dim h As Integer = PictureBox4.Height
        Using g As Graphics = Graphics.FromImage(PictureBox4.Image)
            For i As Integer = 1 To 100
                Using br As New SolidBrush(Color.FromArgb(255, rand.Next(255), rand.Next(255), rand.Next(255)))
                    g.FillEllipse(br, New Rectangle(rand.Next(w \ 2), rand.Next(h \ 2), rand.Next(10 + w \ 2), rand.Next(10 + h \ 2)))
                End Using
        End Using
    End Sub

    Private Sub PictureBox4_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox4.MouseMove
        'Code to drag picturebox4 around using the left mouse button (have to click inside picturebox4)
        Static lpos As Point
        If e.Button = Windows.Forms.MouseButtons.Left Then
            PictureBox4.Location += New Size(e.X - lpos.X, e.Y - lpos.Y)
            lpos = e.Location
        End If
    End Sub

All times are GMT -6. The time now is 06:57 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.