Solved

Drag and Drop using pictureboxes

Posted on 2006-07-18
2
236 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
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
 
LVL 9

Expert Comment

by:Naveen Swamy
ID: 17136408
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 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