1

我尝试下一个方法:

this.AllowDrop = true;
this.DragEnter += new System.Windows.Forms.DragEventHandler(Form_DragEnter);

void Form_DragEnter(object sender, DragEventArgs e)
{
     // here I need to check whether it access .mdb format
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         e.Effect = DragDropEffects.Copy;
     }
     else
     {
         e.Effect = DragDropEffects.None;
     }
 }

怎么查?在DataFormats.没有数据库格式

4

1 回答 1

2
string[] FileList;

if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
    FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
}
else if (e.Data.GetDataPresent(DataFormats.StringFormat))
{
    FileList = new string[] {e.Data.GetData(DataFormats.StringFormat, false).ToString()};
}
else
{
    return;
}

然后遍历字符串数组检查文件扩展名

于 2012-11-22T23:36:40.000 回答