获取文件拖到Windows窗体窗体中的路径 [英] Get the path of a file dragged into a Windows Forms form

查看:106
本文介绍了获取文件拖到Windows窗体窗体中的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序需要用户将文件从 Windows  Explorer 拖入应用程序窗口( Windows窗体表单)。有没有办法在C#中读取文件的文件名,路径和其他属性?

I am developing an application which requires the user to drag a file from Windows Explorer into the application window (Windows Forms form). Is there a way to read the file name, path and other properties of the file in C#?

推荐答案

您可以捕获DragDrop事件并从那里获取文件。一些东西:

You can catch the DragDrop event and get the files from there. Something like:

void Form_DragDrop(object sender, DragEventArgs e)
{
    string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);

    //more processing
}

这篇关于获取文件拖到Windows窗体窗体中的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆