简体   繁体   中英

Drag and Drop from Explorer not working for C# Winforms App

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

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
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM