Embarrassed: Drag and drop III

Ok, I feel like an idiot but I am still confused.  Here is clearly what I am looking for.  I have the picture of a car (car.jpg).  I want this picture to be on Form1 and add a couple of graphic pictures (graphic1.jpg, graphic2.jpg) to be able to drag and drop on that car picture on the same form.  I also want to be able to drag and drop the same graphic picture numerous times if I would like.  Please, what exactly should my code look like (EXACTLY!!!!, PLEASE!!!!)??
lpetrowiczAsked:
Who is Participating?
 
Mark_FreeSoftwareCommented:
created a nice example for you

to add more items, copy the picturebox pItem again and again and again
until you have enough items (make sure it is an ARRAY)


2 options:
option one,
get the (zipped) example from:
https://filedb.experts-exchange.com/incoming/ee-stuff/378-image_example.zip

option two,

open a new project

Add one big picturebox (let's call it pCar)
give it a nice car picture

add another picturebox (pItem)
give it a nice picture (a rim or somthing)

COPY this picturebox
ANSWER YES to the Question about control array
this is very important!!!!!!
now give this one a nice rim also


create a new picturebox
pArr
properties:
Index: 0    !!!!IMPORTANT!!!!
Visible: false   (not important, it looks better this way)

now paste this code:

Option Explicit
'api used to move picturebox:
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1



Private Sub pArr_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
   'if left button is down
   If Button = vbLeftButton Then
      'dunno why it needs this:
      ReleaseCapture
      'send the move message:
      SendMessage pArr(Index).hwnd, WM_NCLBUTTONDOWN, 2, 0&
   End If
End Sub

Private Sub pArr_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
   'Right button = remove!
   If Button = vbRightButton Then
      'can't remove items created in design so hide it
      If Index = 0 Then
         pArr(Index).Visible = False
      Else
         'else unload it
         Unload pArr(Index)
      End If
   End If
End Sub

Private Sub pItem_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
   'grab the last item in the array:
   With pArr(pArr.UBound)
      'remove border:
      .BorderStyle = 0
      .Appearance = 0
      'move it to the position of the current item!
      .Move pItem(Index).Left, pItem(Index).Top
      'have it fit the picture automatic:
      .AutoSize = True
      'copy the picture from the current item
      .Picture = pItem(Index).Picture
      'let's show it:
      .Visible = True
      'would be nice if it is not behind some crap:
      .ZOrder 0
      'send the first message to get the moving started
      pArr_MouseMove pArr.UBound, vbLeftButton, Shift, X, Y
   End With
   'load a new item for the next time:
   Load pArr(pArr.UBound + 1)
End Sub
0
 
justchat_1Commented:
Mark:
Great answer but just wanna reference you to part II that I worked on in case you wanted some more background on the project... I tried to help but couldnt meet all the requirements:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21912485.html?query=drag+and+drop+II&clearTAFilter=true
0
 
Mark_FreeSoftwareCommented:

well, since he didnt provide a link, i assumed he just wanted some fool-proof code ;)
0
 
lpetrowiczAuthor Commented:
Mark,

Thank you very much for the download.  That is exactly what I was looking for.  I just couldn't pick up on this code.  I wish I could give you more points.  You have helped me out more than you could imagine.

Very respectfully,
Lawrence
0
 
Mark_FreeSoftwareCommented:

thanks for the points, and happy coding!


and i'm glad you like it ;)
0
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.

All Courses

From novice to tech pro — start learning today.