我使用以下代码拖放单个文件.
private void FormRegion2_DragEnter_1(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{ e.Effect = DragDropEffects.Copy; }
// or this tells us if it is an Outlook attachment drop
else if (e.Data.GetDataPresent("FileGroupDescriptor"))
{ e.Effect = DragDropEffects.Copy; }
// or none of the above
else
{ e.Effect = DragDropEffects.None; }
}
private void FormRegion2_DragDrop_1(object sender, DragEventArgs e)
{
string[] fileNames = null;
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
{
fileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string fileName in fileNames)
{
}
}
else if (e.Data.GetDataPresent("FileGroupDescriptor"))
{ …Run Code Online (Sandbox Code Playgroud)