【发布时间】:2011-05-20 15:13:03
【问题描述】:
我正在使用 C# 2.0,并且我创建了一个资源管理器树,我可以将信息从该树拖到 Windows 窗体中。现在,当我从我使用的树视图中拖动时,它执行DoDragDrop(selectedpath, DragDropEffects.Copy);
当我在主窗体中捕获事件时,它被列为字符串。我能够完成这项工作,但我希望它的执行方式与我从 Windows 资源管理器窗口中拖动文件的方式相同,如下所示
Array name = (Array)e.Data.GetData(DataFormats.FileDrop);
// Ensure that the list item index is contained in the data.
if (e.Data.GetDataPresent(typeof(System.String)))
{
Object item = (object)e.Data.GetData(typeof(System.String));
// Perform drag-and-drop, depending upon the effect.
if (e.Effect == DragDropEffects.Copy ||
e.Effect == DragDropEffects.Move)
{
//// Insert the item.
//if (indexOfItemUnderMouseToDrop != ListBox.NoMatches)
// ListDragTarget.Items.Insert(indexOfItemUnderMouseToDrop, item);
//else
// ListDragTarget.Items.Add(item);
}
}
我尝试过 DoDragDrop(new DataObject(selectedfile),DragDropEffects.Copy) 但这不起作用。
【问题讨论】:
-
至少告诉那个人你为什么拒绝他的问题!
-
谢谢。我已经搜索了答案,但似乎没有找到。
-
我认为没有理由对这个问题投反对票。 +1
标签: c# .net winforms drag-and-drop