Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Drag and Drop using pictureboxes

Hi, everyone!!
I have a problem, i am doing an aplicattion in vb.net and i need to drag and drop one or more images over another images. i'm doing these using a picturebox with one of the images and another picture box with the other image. but i don't know how to do the drag and drop.
Can everybody help me???
Thank you
0
MartinCordoba
Asked:
MartinCordoba
1 Solution
 
jjardineCommented:
Your first step would be to set the receiving picture boxes    "AllowDrop" property to true.

Then in your source picture box you need to add code to the Mouse Down Event to start the drag like this

Public Sub PictureBox1_MouseDown(sender as Object, e as System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
  Me.DoDragDrop(PictureBox1.Image,DragDropEffects.Copy)
End Sub

In your Receiving Picture Boxes you want to code the DragEnter and DragDrop Events Like This.

Public Sub PictureBox2_DragEnter(sender as Object, e as System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragEnter
  If e.Data.GetDataPresent(GetType(Image)) Then
    e.Effect = DragDropEffects.Copy
  Else
   e.Effect = DragDropEffects.None
  End If
End Sub

Public Sub PictureBox2_DragDrop(sender as Object, e as System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop
  PictureBox2.Image = DirectCast(e.Data.GetData(GetType(Image)),Image)
End Sub

This is a simple scaled down version.   Hope this helps get you started.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now