Drag ' n ' Drop from Listview to Panel

I am currently building an application that allows the user to set up the dimensions of a room, then add pieces of funiture to the room (all to scale).
I was wanting to use the listview control for showing the furniture items, and a panel control is used as a 'snap grid' room.
Now the icons in the listview are not the same ones to be dragged onto the panel. What I would like to be able to do is either drag n drop the correctly scaled piece of furniture onto the panel, or have it appear on the panel when selected( much like a Real time strategy game). The user can then position it, rotate etc as needed.

Background out of the way, how do I select the right size graphic when I click on the listview, display it for dragging and drop it onto the panel. I have only 3 ratios to work with (1:1, 7:10, 1:2), which is determined when the room dimensions are chosen. May initial thoughts is to just build graphics in all 3 dimensions and stick them in a imagelist, on selection choose the correct sized graphic and then create a picturebox on the panel to stick it in. Sounds okay in theory, but VB.NET is not VB6, which is where I'm falling down. Any help is appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Not sure exactly where you want help at...

Seperate PictureBoxes for each piece of furniture will make moving them easy.  Also, if you set the AutoScroll property of the Panel to True then you have an instant scrollable room.

You can use the DrawImage() function to scale your graphics for the different ratios.

Milkus1Author Commented:
Thanks IdleMind,
what I need help with is how do I make the picturebox array at runtime, in VB.NET and the handlers for the boxes. Or display the correct graphic for dragging onto the panel? A room may have 50 pieces of furniture, all which need to be tracked, rotated, snapped to a grid. etc.
If I could do it like SIMCITY or Warcraft type mechanics I would be very happy. You know where the 'piece' is moved around with the cursor until its dropped.
Currently I can click an Item and make 1 picturebox appear in the room with the correct graphic, but not an array of them.

 I'll check into the drawimage function to handle the sizing issue.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is a very simple example of how to add multiple, draggable pictureboxes to a panel:

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.Button1 = New System.Windows.Forms.Button
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.Panel1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Panel1.AutoScroll = True
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Panel1.Location = New System.Drawing.Point(80, 8)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(376, 376)
        Me.Panel1.TabIndex = 0
        Me.Button1.Location = New System.Drawing.Point(8, 8)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(64, 40)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Add Image"
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(464, 390)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private startPoint As Point

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
        If OpenFileDialog1.ShowDialog = DialogResult.OK Then
                Dim pb As New PictureBox
                pb.Image = Image.FromFile(OpenFileDialog1.FileName)
                pb.Location = New Point(0, 0)
                pb.Size = New Size(100, 100)
                AddHandler pb.MouseDown, AddressOf pb_MouseDown
                AddHandler pb.MouseMove, AddressOf pb_MouseMove
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error Loadinng Image")
            End Try
        End If
    End Sub

    Private Sub pb_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = MouseButtons.Left Then
            Dim pb As PictureBox = CType(sender, PictureBox)
            startpoint = pb.PointToScreen(New Point(e.X, e.Y))
        End If
    End Sub

    Private Sub pb_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = MouseButtons.Left Then
            Dim pb As PictureBox = CType(sender, PictureBox)
            Dim curPoint As Point = pb.PointToScreen(New Point(e.X, e.Y))
            pb.Left = pb.Left + (curPoint.X - startPoint.X)
            pb.Top = pb.Top + (curPoint.Y - startPoint.Y)
            startPoint = curPoint
        End If
    End Sub

End Class

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Milkus1Author Commented:
Legend!!! Thanks Idle Mind...all points for you this looks exactly what I need!
I love this site, and guys like you who help out.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.