需要配置参数,选择目标-》右侧属性中的AllowDrop=true
其次在右侧的事件中找到:DragDrop,DragEnter分别把下面两句拖进去
主要是这两处代码:
private void Form1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.All; } else { e.Effect = DragDropEffects.None; } } private void Form1_DragDrop(object sender, DragEventArgs e) { string text = ((Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); textBox1.Text = text; }