Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am using windows 7 and visual studio to develop C# applications, but I've run into an annoying roadblock. I'm trying to use the DragDrop Event on a form with no objects in it, but when I try to drag a file into it, it always has a "blocked" cursor and wont let me drop the file. It worked for me in Windows XP and I recently upgraded and found I am unable to drop the file any more. If someone could provide assistance for this or refresh me on how to do it since it was a while ago since I've tried it last, it would be greatly appreciated. Thanks.
Posted

Did you try ShellObjectCollection of API CodePack in Windows 7. I think there is considerable amount of enhancement is made in Shell of Win7 and there is also a sample application of doing exactly this in the codepack.

I think you should try the sample definitely.
Check here:
http://code.msdn.microsoft.com/WindowsAPICodePack[^]

:thumbsup:
 
Share this answer
 
Listen for DragEnter event. When that fires, set e.Effect to some allowed effect. Then your form should allow drops.
 
Share this answer
 
well, what i got from the net is that "Windows 7 User Account Control does not allow drag and drop". Link to the site:
http://weblogs.asp.net/jeffwids/archive/2010/04/28/windows-7-user-account-control-does-not-allow-drag-and-drop.aspx
 
Share this answer
 
Judah's solution worked for me.

I've just spent two hours reading up on UAC, manifests and a whole bunch of stuff to solve this and got nowhere. The DragEnter would always fire but not the DragDrop event. I hadn't coded the full event, just set a message box to fire on the event.

I read Judah's post with skepticism but it worked. Thanks very much.

A snippet of code to illustrate (assuming you have a panel called "panelDropTarget" with "AllowDrop" property set to true):

C#
private void panelDropTarget_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
        e.Effect = DragDropEffects.Move;
    }
}

private void panelDropTarget_DragDrop(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
        MessageBox.Show("DragDrop fired");
    }
}
 
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