[C#][Original] Drag and drop to get the file path

Set the property AllowDrop of the Form/control to true. This method is applicable to any control
    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; 


 

 




         }

Guess you like

Origin blog.csdn.net/FL1623863129/article/details/113529741