我目前正在使用文件对话框导出文件,但我想知道如何使用拖放功能导出文件。我无法弄清楚如何获取项目被删除的文件路径。这是我用于打开文件对话的代码,如果需要的话。
if (this.listView1.SelectedItems.Count > 0)
{
ListViewItem item = this.listView1.SelectedItems[0];
string text = this.faderLabel8.Text;
if (!text.EndsWith(@"\"))
{
text = text + @"\";
}
using (SaveFileDialog dialog = new SaveFileDialog())
{
if (dialog.ShowDialog() == DialogResult.OK)
{
Jtag.ReceiveFile(item.SubItems[0].Text, text + item.SubItems[0].Text);
}
}
}
答案 0 :(得分:0)
如果你希望它通过"拖放"你需要某种图形界面,在它们所在的容器中显示文件,然后在另一个容器中显示你要移动它们的位置。当您使用鼠标突出显示某个项目时,您可以将它们添加到itemList中,然后在删除它们时复制它们。如果删除突出显示,只需确保列表清空一次。
答案 1 :(得分:0)
您不需要删除文件的路径。相反,您需要创建一个临时文件。
//(This example is uses WPF/System.Windows.DragDrop)
//Create temporary file
string fileName = "DragDropSample.txt";
var tempPath = System.IO.Path.GetTempPath();
var tempFilePath = System.IO.Path.Combine(tempPath, fileName);
System.IO.File.WriteAllText(tempFilePath, "Testing drag and drop");
//Create DataObject to drag
DataObject dragData = new DataObject();
dragData.SetData(DataFormats.FileDrop, new string[] { tempFilePath });
//Initiate drag/drop
DragDrop.DoDragDrop(dragSourceElement, dragData, DragDropEffects.Move);
对于WinForms示例和更多详细信息,请参阅: Implement file dragging to the desktop from a .net winforms application?