Solved

Drag and Drop using pictureboxes

Posted on 2006-07-18
2
239 Views
Last Modified: 2010-04-23
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
Comment
Question by:MartinCordoba
[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
2 Comments
 
LVL 14

Accepted Solution

by:
jjardine earned 500 total points
ID: 17135150
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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