I have a form and I want to be able to drop files on it. I have the following code:
private void Form1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
I want the cursor to change only when I am dropping files, and not when I drop directories. The above code changes it for directories as well. What am I doing wrong? Is there any data format for files, or should I simply try to check the object I get in e.Data for extension?
You should check the data using
File.Exists? I think it will return true if it is a file, and false if it isn’t.Here is an example from MSDN: