marduck19
marduck19

Reputation: 54

drag and drop picturebox between forms

what is the best way to do this y need move a picturebox and drop in the other form y used this for move my picture

private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
         x = e.X;
         y = e.Y;
     }
 }

private void pictureBox2_MouseMove(object sender, MouseEventArgs e)  
{
    if (e.Button == MouseButtons.Left)
    {
        pictureBox2.Left += (e.X -x);
        pictureBox2.Top += (e.Y - y);
    }
 }

Upvotes: 1

Views: 1054

Answers (1)

Joseph
Joseph

Reputation: 65

The best way is to use the Drag and Drop eventing. http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dragdrop.aspx

A good article describing nearly exactly what I believe you're trying to do is here: http://ondotnet.com/pub/a/dotnet/2002/11/11/dragdrop.htm

Hope that helps.

Upvotes: 1

Related Questions