VBForums  

VB Wire News



Go Back   VBForums > Visual Basic > Classic Visual Basic
Register FAQ Members List Calendar Today's Posts Tech Jobs

Reply Post New Thread
Thread Tools Search this Thread Display Modes
Old 01-05-2004, 05:35 PM   #1
Trancedified
Lively Member

Join Date: Oct 03
Posts: 89
Trancedified is an unknown quantity at this point (<10)
Drag & drop (Swapping images) in picturebox

Hello,

I ran a search on drag and drop but didn't quiet find what I was looking for:

I have 2 Pictureboxes where images are already preloaded into.
However, if needed I will have to rearrange where each picture is (swapping)

So if I click and drag the image from picturebox1 to picturebox2, I'd like the images to swap places; picturebox1's image get's dropped into picturebox2, and picturebox2's image get's dropped into picturebox1.

So far, if I did the above example... picturebox1's image replaces picturebox2's image.

Here's what I got:

VB Code:
  1. Private Sub Picture2_DragDrop(Source As Control, X As Single, Y As Single)
  2.  
  3.       Picture2.Picture = Source.Picture
  4.       Set Source.Picture = Nothing
  5.  
  6. End Sub
  7.  
  8. Private Sub Picture4_DragDrop(Source As Control, X As Single, Y As Single)
  9.  
  10.       Picture4.Picture = Source.Picture
  11.       Set Source.Picture = Nothing
  12.  
  13. End Sub

Any solutions to this problem?

Thanks

Chris
Trancedified is offline   Reply With Quote
Old 01-05-2004, 05:51 PM   #2
brucevde
PowerPoster

Join Date: Oct 02
Location: British Columbia
Posts: 7,182
brucevde is a splendid one to behold (700+) brucevde is a splendid one to behold (700+) brucevde is a splendid one to behold (700+) brucevde is a splendid one to behold (700+) brucevde is a splendid one to behold (700+) brucevde is a splendid one to behold (700+) brucevde is a splendid one to behold (700+)
In order to swap you need to temporarily store the current picture before changing it. Note it may depend on your method of loading the picture and the following assumes the same size pictures

VB Code:
  1. Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
  2.     Dim objPic As StdPicture
  3.    
  4.     Set objPic = Picture1.Picture
  5.     Set Picture1.Picture = Source.Picture
  6.     Set Source.Picture = objPic
  7. End Sub
  8.  
  9. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  10.     Picture1.Drag vbBeginDrag
  11. End Sub
  12.  
  13. Private Sub Picture2_DragDrop(Source As Control, X As Single, Y As Single)
  14.     Dim objPic As StdPicture
  15.  
  16.     Set objPic = Picture2.Picture
  17.     Set Picture2.Picture = Source.Picture
  18.     Set Source.Picture = objPic
  19. End Sub
  20.  
  21. Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  22.     Picture2.Drag vbBeginDrag
  23. End Sub
brucevde is online now   Reply With Quote
Old 01-05-2004, 06:13 PM   #3
Trancedified
Lively Member

Join Date: Oct 03
Posts: 89
Trancedified is an unknown quantity at this point (<10)
great it works! thanks a lot

Last edited by Trancedified : 01-05-2004 at 06:21 PM.
Trancedified is offline   Reply With Quote
Reply


Go Back   VBForums > Visual Basic > Classic Visual Basic

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