move one picturebox inside another
move one picturebox inside another
move one picturebox inside another
move one picturebox inside another
move one picturebox inside another
move one picturebox inside another move one picturebox inside another move one picturebox inside another move one picturebox inside another move one picturebox inside another move one picturebox inside another move one picturebox inside another move one picturebox inside another
move one picturebox inside another move one picturebox inside another
move one picturebox inside another
Go Back  Xtreme Visual Basic Talk > > > move one picturebox inside another


Reply
 
Thread Tools Display Modes
  #1  
Old 01-02-2018, 09:43 AM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 310
Default move one picturebox inside another


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.
Attached Images
File Type: gif image schema.gif (17.4 KB, 4 views)
Reply With Quote
  #2  
Old 02-13-2018, 10:13 PM
passel's Avatar
passelmove one picturebox inside another passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,031
Default

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.
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
            Next
        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)
        Else
            lpos = e.Location
        End If
    End Sub
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply

Tags
drag, pic2, inside, pic1, image, vb6, moment, loads, region, managed, full-size, quick, attached, disappears, diagram, hop, clearer, bottom, solution, passels, adapted, left, top, code, mouse


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
move one picturebox inside another
move one picturebox inside another
move one picturebox inside another move one picturebox inside another
move one picturebox inside another
move one picturebox inside another
move one picturebox inside another move one picturebox inside another move one picturebox inside another move one picturebox inside another move one picturebox inside another move one picturebox inside another move one picturebox inside another
move one picturebox inside another
move one picturebox inside another
 
move one picturebox inside another
move one picturebox inside another
 
-->