C# WinForm拖入文件到窗体,得到文件路径
2020-12-13 02:10
标签:winform c style class blog code 窗体上添加以上2个事件即可。DragEnter、DragDrop C# WinForm拖入文件到窗体,得到文件路径,搜素材,soscw.com C# WinForm拖入文件到窗体,得到文件路径 标签:winform c style class blog code 原文地址:http://www.cnblogs.com/yzeng/p/3761705.html
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] rs = (string[])e.Data.GetData(DataFormats.FileDrop);
MessageBox.Show(rs[0]);
}
}
private void Form1_DragEnter_1(object sender, DragEventArgs e)
{
//只允许文件拖放
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}