Click here to Skip to main content
16,020,701 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a window project in which i took one form and in that i took one panel.
Now story begins......
I want some message box prompt e.g "XYZ file is drag-dropped to the panel" when i select one file from my desktop and dragged it to the panel...How can i do that?????? my code is C#.NET. :doh:
Posted

Check out this article:

Drag and Drop Image in C#.NET[^]

It's for images but I'm sure you can adapt it to meet your requirements.

Also Google gives you many hits:

http://www.google.co.uk/search?hl=en&q=drag+file+to+window+%2B+c%23.net&meta=[^]
 
Share this answer
 
Hi,

1. Set following property for Panel to True (if it was set to false)
"AllowDrop"
2. Then there are two events for which you that you should write event handler. One is DragEnter and DragDrop. (a) DragEnter decides whether data going to be draged is valid data and if valid data then (b)DragDrop accets the data dragged onto it.

Therefore eventhandler of DragEnter should be for checking data and in DragDrop you write your code to process data after it is accepted.


C#
private void panel1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
                e.Effect = DragDropEffects.Copy; // Okay
            else
                e.Effect = DragDropEffects.None; // Unknown data, ignore it

        }


C#
private void panel1_DragDrop(object sender, DragEventArgs e)
        {
            MessageBox.Show("XYZ file is drag-dropped to the panel");
        }





Hope that helps you,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900