Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WinForms DragEnter never fires

I'm puzzled with this. I attempted implementing drag and drop on a DataGridView. Failing to see any events fired, I tried a simple form, with a text box.

I would like to be able to drag files or folders from Windows Explorer.

I'm missing something because these events never fire. I did read about DragEvents, Windows 7 and UIPI but I still couldn't get around this.

I'm out of ideas and I welcome your suggestions.

public Form1()
{
    InitializeComponent();
    this.AllowDrop = true;
    textBox1.AllowDrop = true;
    textBox1.DragEnter += new DragEventHandler(textBox1_DragEnter);
    textBox1.DragDrop += new DragEventHandler(textBox1_DragDrop);
    textBox1.DragOver += new DragEventHandler(textBox1_DragOver);
}

void textBox1_DragOver(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}

void textBox1_DragDrop(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}

void textBox1_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}

It seems that this should work. I have a clean install on WP7 64 - with all updates, I don't have virus or malware protection running, or anything (to my knowledge) which could prevent these events firing.

like image 447
nullable Avatar asked Jan 08 '12 10:01

nullable


2 Answers

I had the same issue. it was only because I was debugging from a "run as administrator" session. I think that since VISTA there is a security that prevents from dropping to a privileged application.

like image 97
fumble Avatar answered Sep 27 '22 19:09

fumble


I found that while I was running my Forms application in debug mode from Visual Studio, it didn't work. Only when I ran it outside of VS does it work perfectly. Presumably this is also something to do with security on Windows 7 (and possibly later versions).

like image 42
andyb Avatar answered Sep 27 '22 21:09

andyb