private void panel1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Text)) { e.Effect = DragDropEffects.Copy; } }
private void textBox1_DragDrop(object sender, DragEventArgs e) { string fileName = (string)e.Data.GetData(DataFormats.Text); textBox1.Text = fileName; }In this example, we are retrieving the file name that is being dragged and dropped onto a textbox control. We then set the Text property of the textbox to the file name so that the user can see which file was dropped. The package library for the System.Windows.Forms DragEventArgs class is the .NET Framework Class Library.