文章目录

设置Form1的属性 AllowDrop=true

设置 DragDrop 和 DragEnter事件,需要在DragEnter事件中设置 e.Effect = DragDropEffects.Move 然后才能在 DragDrop中接收内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
private void Form1_DragDrop(object sender, DragEventArgs e)
{
textBox1.Text = "";
Array array = ((System.Array)e.Data.GetData(DataFormats.FileDrop));
for(int i = 0; i < array.Length; i++)
{
textBox1.Text += array.GetValue(i).ToString() +"\r\n";
}
}

private void Form1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
文章目录