winform(C#)拖拽实现获得文件路径

设置Form的AllowDrop为true

 private void Form1_DragDrop(object sender, DragEventArgs e)
        
{
            
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            MessageBox.Show(path);   

        }


        
private void Form1_DragEnter(object sender, DragEventArgs e)
        
{
            
if (e.Data.GetDataPresent(DataFormats.FileDrop))
                e.Effect 
= DragDropEffects.Link;
            
else e.Effect = DragDropEffects.None; 


        }
原文地址:https://www.cnblogs.com/ahuo/p/1164028.html