Image Drag and Drop in WindowsApplication using C#.

Image Drag and Drop using C#
----------------------------

AllowDrop Property set to True in which control you have to drag the image.

For Ex,

Here is I'm going to drag an image from a picture box in to a panel.

Step 1:
Set AllowDrop property to True for panel control.

Step 2:

In picturebox mouse down event, write the code as follows,


pictureBox1 = (PictureBox)sender;
DoDragDrop(pictureBox1.Image, DragDropEffects.Copy);

Step 3:

In panel Drag_DragEnter event, write the following,


if (e.Data.GetDataPresent(typeof(Bitmap)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}

Step 4:

In panel Drag_DragDrop event, write the following,

Panel pnlDroggedTheme = (Panel)sender;
pnlDroggedTheme.Height = panel1.Height;
pnlDroggedTheme.Width = panel1.Width;
pnlDroggedTheme.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));


Run the program, that's it...

...S.VinothkumaR.

2 comments:

Muhammad said...

i tried but didn't work with me, thanks anyway

mehmet said...

hi..
I'm doing spider soliatire..
how can I drag-drop from a picturebox
to a picturebox??

can you help me??