0
votes

I have a C# Winforms app in which I am trying to implement drag and drop of files and folders onto a label in a GroupBox, but I get a black No Entry icon when I try and drag files or folders from File Explorer onto it, or the containing form. The environment is Win 10 VS 2013.

I have the following without success:

1) Tried running the compiled app in a non-elevated mode to get around the fact that I am running VS 2013 as Administrator and File Explorer is run as a user account.

2) Set the Form in which the label in the group box is placed to AllowDragDrop.

3) Setting UAC to never notify me when apps make changes via Control Panel->User Accounts

1
Is the AllowDrop property also set to true on the receiving Control(s)? Have you subscibed to the DragDrop and (at least) the DragEnter events of the control(s) that should accept the drop? How is the e.Effect set? Do you have a procedure that checks whether the e.Data formats are compatible with what you can/want to manage? - Jimi
Yes, Allow Drop set to true, but the events are never entered and the icon remains at No Entry whenever the cursor is moved over the form - SimonKravis
Post the code you're using, then. - Jimi
--edit i see there is a blog post on MSDN have you seen this ? Why Doesn’t Drag-and-Drop work when my Application is Running Elevated - HeadJ.E.M.
Have found an old example (downloaded in 2014) from .Net 2.0 which works - will post details. Original code seems to have disappeared - SimonKravis

1 Answers

0
votes

The problem was that additional code was needed in the label_DragEnter Event to set DragDropEvents, as well as enabling DragDrop for the label:

private void lblFile_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
    }