如题:有人说把窗体的AllowDrop设置为True就可以,问题是我生成的DragDrop事件处理方法没反应,DragEnter倒是触发到了。我的目的是当用户拖放一个文件到窗体上的时候获取该文件的路径,然后

解决方案 »

  1.   


    private void textBox1_DragDrop(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop)) 
        {
            string[] paths = (string[])e.Data.GetData(DataFormats.FileDrop); 
            // paths[0] 为第1个文件全路径
        }
    }
      

  2.   

    我的问题是:private void textBox1_DragDrop(object sender, DragEventArgs e)
    {
        MessageBox.Show("拖放");    //没反应,AllowDrop已设置为true
    }
      

  3.   


    private void textBox1_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            e.Effect = DragDropEffects.Copy;
        }
        else
        {
            e.Effect = DragDropEffects.None;
        }
    }private void textBox1_DragDrop(object sender, DragEventArgs e) 

        MessageBox.Show("拖放");
    }