我的表单上有一个允许拖放的面板。我已将代码写入DragEnter
和DragDrop
事件,上次检查时它们工作正常。但是现在当我在面板上拖动一个文件时,我得到禁用的光标并且事件不再被触发。我查看了整个项目,看看我是否在某个地方禁用了AllowDrop
,但我没有。
以下是我的活动以及他们正在执行的活动:
this.pnlNoPostbagFolder.AllowDrop = true;
this.pnlNoPostbagFolder.DragDrop += new System.Windows.Forms.DragEventHandler(this.pnlNoPostbagFolder_DragDrop);
this.pnlNoPostbagFolder.DragEnter += new System.Windows.Forms.DragEventHandler(this.pnlNoPostbagFolder_DragEnter);
private void pnlNoPostbagFolder_DragDrop(object sender, DragEventArgs e)
{
FileListDragDrop(sender, e);
}
private void pnlNoPostbagFolder_DragEnter(object sender, DragEventArgs e)
{
FileListDragEnter(sender, e);
}
private void FileListDragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void FileListDragDrop(object sender, DragEventArgs e)
{
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
for (int i = 0; i < s.Length; i++)
{
if (Path.GetExtension(s[i]).Equals(".csv", StringComparison.InvariantCultureIgnoreCase) || Path.GetExtension(s[i]).Equals(".sql", StringComparison.InvariantCultureIgnoreCase))
{
string source = s[i];
string destination = Common.Conf.PostbagFolderLocation + "\\" + Path.GetFileName(s[i]);
if (File.Exists(destination))
{
DialogResult dr = MsgBox.Show(string.Format("A file named '{0}' already exists in the Postbag folder. Overwrite?", Path.GetFileName(s[i])), "File Exists", MsgBox.Buttons.YesNo, MsgBox.Icon.Question);
if (dr == DialogResult.Yes)
{
File.Copy(source, destination, true);
RefreshPostbagFolder();
}
}
File.Copy(source, destination, true);
}
else
MsgBox.Show("File extension not supported", "Add File", MsgBox.Buttons.OK, MsgBox.Icon.Error);
}
}
答案 0 :(得分:2)
您的所有代码似乎都没问题,我的机器中的代码也没有任何问题,这似乎是UAC问题: