这是代码。我试图在我的硬盘上标记 40 个文件,然后我将它们拖到列表框,但它只添加了一个文件。我想在拖动它们时将所有选定的文件添加到我的硬盘上,我该怎么做?
private void listBox1_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
bool bfound = false;
for (int i = 0; i < files.Length; i++)
{
FileInfo fi = new FileInfo(files[i]);
//add more extensions here
if (fi.Extension == ".jpg" || fi.Extension == ".png" || fi.Extension == ".bmp" || fi.Extension == ".emf" || fi.Extension == ".gif" || fi.Extension == ".ico" || fi.Extension == ".tiff"
|| fi.Extension == ".wmf" || fi.Extension == ".exif")
{
bfound = true;
break;
}
}
if (bfound)
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
else
e.Effect = DragDropEffects.None;
}