Link to home
Start Free TrialLog in
Avatar of Cherryex
Cherryex

asked on

How to Undo DragDrop on DragLeave event

Hi,

I have a row of PictureBoxes side by side on my form.  I am able to drag and drop images between the boxes and display a message when entering and leaving each box.  I would like to be able to start at one box, hold the shift button and move my move over consecutive boxes that I want to copy to and then copy to all of them when I dragdrop at the last box.  Ideally I wanted the boxes I pass over to change colour or display the copy of the image in the first PictureBox.  I decided to use the DragEnter and DragLeave.. copying the image on the DragEnter as the mouse passed over it.  This does work, however if a user started dragging from PictureBox1 and passed over PictureBox2-4 (whilst still holding the shift button) then decided that only PictureBox1-3 should be the same.  They would expect to be able to go back to PictureBox3 and the image from PictureBox4 to return to the previous value.  Can anyone suggest a way to return to the original value in a Picturebox on the DragLeave event, or suggest a better way to acomplish this?  This is my first day using VB.net (only used Access VBA until now), I have also never worked with drag and drop before.....I hope this makes sence it is horrible to explain!  

DragEnter:
        If e.Data.GetDataPresent(DataFormats.Bitmap) Then
            If e.KeyState = 5 Then ' (1 for the mouse and 4 for the shift button)
                Label3.Text = "Drag plus shift"
                e.Effect = DragDropEffects.Copy
                PictureBox4.Image = e.Data.GetData(DataFormats.Bitmap)
            Else
                Label3.Text = "Drag"
                e.Effect = DragDropEffects.Move
            End If
        Else
            e.Effect = DragDropEffects.None
        End If

  DragLeave:
        Label3.Text = "Drag leave"
        Me.PictureBox4.Refresh()
   
Avatar of eventprostrategies
eventprostrategies

Not entirely sure what you haven't gotten to work.  If you can set the Text of some label on the DragLeave event, you can reset the image of the picturebox as well.

let's say you have an ImageList with your original images ...

pb0's default image is imageList1.Images.Item(0)
pb1's default image is imageList1.Images.Item(1) ...

Set the pb's Image to whatever's being dragged to it on DragEnter ...

just reset the pb Image to its default Image (from the ImageList)

However you're storing the images, just reload the pb's Image to its previous image on the DragLeave event.
Avatar of Cherryex

ASKER

This bit that works at the moment is that when the mouse goes over a pb the dragEnter event drops a copy of the image to it, but I can't put it back to the last image on the DragLeave.  It is not a problem with getting something to happen on the DragLeave event (as you said, I can change a label) but I don't know how to put the image back.  

The problem is that there is no default image as such, it will either be blank or it will have an image which was dropped by another pb.  I just need to go back to the last image that it displayed rather than the original, I just want to undo the whole action DragEnter on the DragLeave event.
It might help if I explain what I am trying to do......In the Outlook calender you can block in periods of time for a day, I am trying to do something similar.  I am dragging and dropping a block representing a 1 hour lunch onto my series of pb's (each of which represent 15mins in my day).  

I can presently move the lunchtime block by dragging and dropping it so that instead of from 12.00 til 1.00 it sits in the 1.00 till 2.00 block.  But I also want the ability to expand the lunchtime block by either dragging it over some other blocks so that I covers a 1.5 hr lunch or 2hr lunch etc....
ASKER CERTIFIED SOLUTION
Avatar of eventprostrategies
eventprostrategies

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, (eventprostrategies)

Thanks for the responce, I got pulled off on another project and I am on a training course tomorrow so I haven't had much of a chance to work with it but it looks good .......thanks for the extra info :-) this is my first job as a developer and I need all the help I can get.