Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Embarrassed: Drag and drop III

Posted on 2006-07-12
5
Medium Priority
?
243 Views
Last Modified: 2010-04-30
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!!!!)??
0
Comment
Question by:lpetrowicz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 2000 total points
ID: 17096064
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
 
LVL 9

Expert Comment

by:justchat_1
ID: 17096532
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
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 17097593

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

Author Comment

by:lpetrowicz
ID: 17100152
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
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 17101665

thanks for the points, and happy coding!


and i'm glad you like it ;)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question