C# - App - How to Drag and Drop from the desktop to a Panel in a Form?
DiggBlinkRedditDeliciousTechnorati
question by Alfonso2968 | Hard
Hello,
I am New here and fairly new to programming.
I have searched everything and all I can find is how to drag and drop within a form from panel to panel.
What I need to do is Drag an image from the desktop or from an open folder to a panel on my form.
This will be done for a few images and then on Buttonclik I need to save each image in its own folder.
Any help is much appreciated.
Here is what I have on the events - for d&d
This allows me to drag and drop within the form but trying to drag from desktop to panel1 doesn't work.
Code: ( text )
1.
private void panel_DragDrop(object sender, DragEventArgs e)
2.
{
3.
//target control will accept data here
4.
Panel destination = (Panel)sender;
5.
destination.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
6.
7.
}
8.
9.
10.
11.
12.
private void panel_DragEnter(object sender, DragEventArgs e)
13.
{
14.
//As we are interested in Image data only we will check this as follows
15.
if (e.Data.GetDataPresent(typeof(Bitmap)))
16.
{
17.
e.Effect = DragDropEffects.Copy;
18.
}
19.
else
20.
{
21.
e.Effect = DragDropEffects.None;
22.
}
23.
24.
}
25.
26.
27.
private void panel_MouseDown(object sender, MouseEventArgs e)
28.
{
29.
//we will pass the data that user wants to drag DoDragDrop method is used for holding data
30.
//DoDragDrop accepts two paramete first paramter is data(image,file,text etc) and second paramter
31.
//specify either user wants to copy the data or move data
32.
33.
Panel source = (Panel)sender;
34.
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
35.
36.
37.
}
Post reply
Subscriptions
Got a Desktop Development Question?
Just Sign Up and ask the top Desktop Development experts!
|