|
-
Jan 5th, 2004, 06:35 PM
#1
Thread Starter
Lively Member
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:
Private Sub Picture2_DragDrop(Source As Control, X As Single, Y As Single)
Picture2.Picture = Source.Picture
Set Source.Picture = Nothing
End Sub
Private Sub Picture4_DragDrop(Source As Control, X As Single, Y As Single)
Picture4.Picture = Source.Picture
Set Source.Picture = Nothing
End Sub
Any solutions to this problem?
Thanks
Chris
-
Jan 5th, 2004, 06:51 PM
#2
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:
Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
Dim objPic As StdPicture
Set objPic = Picture1.Picture
Set Picture1.Picture = Source.Picture
Set Source.Picture = objPic
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Drag vbBeginDrag
End Sub
Private Sub Picture2_DragDrop(Source As Control, X As Single, Y As Single)
Dim objPic As StdPicture
Set objPic = Picture2.Picture
Set Picture2.Picture = Source.Picture
Set Source.Picture = objPic
End Sub
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture2.Drag vbBeginDrag
End Sub
-
Jan 5th, 2004, 07:13 PM
#3
Thread Starter
Lively Member
great it works! thanks a lot
Last edited by Trancedified; Jan 5th, 2004 at 07:21 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|