将文件拖动到表单中并获取文件地址 [英] drag file in form and get file address

查看:66
本文介绍了将文件拖动到表单中并获取文件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 如何找到一个拖到表单中的文件的文件地址?

非常感谢,祝您有美好的一天?

Hi How can i find file address of one file that dragged to a form ?

thanks a lot and have a good day ?

推荐答案

尝试:

Try:

private void frmMain_Load(object sender, EventArgs e)
    {
    AllowDrop = true;
    DragEnter += new DragEventHandler(frmMain_DragEnter);
    DragDrop += new DragEventHandler(frmMain_DragDrop);
    }
void frmMain_DragEnter(object sender, DragEventArgs e)
    {
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
        // File - is fine
        e.Effect = DragDropEffects.Copy;
        }
    else
        {
        // Unknown data, ignore it
        e.Effect = DragDropEffects.None;
        }
    }
void frmMain_DragDrop(object sender, DragEventArgs e)
    {
    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
    foreach (string file in files)
        {
        Console.WriteLine(file);
        }
    }


阅读此内容

将文件从Windows资源管理器拖放到Windows窗体 [ ^ ]

希望这会有所帮助,如果是,则接受并投票回答,否则返回您的查询
--Rahul D.
Read this

Drag and Drop files from Windows Explorer to Windows Form[^]

Hope this helps , if yes then accept and vote the answer otherwise revert back with your queries
--Rahul D.


这篇关于将文件拖动到表单中并获取文件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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