相信CSDNer中有很多实用过飞鸽吧?
当要使用飞鸽向对方发送文件或文件夹的时候,
我们可以先到想要发送的文件夹下,选择想要的,
然后就可以拖动到飞鸽的传送窗口上,那样就可以传送了请问用C#怎么实现,只要能获得拖放的文件和文件夹名称即可?
也可以说:在Windows里多个窗口间文件夹的拖放,怎么实现?

解决方案 »

  1.   

    参考如下代码:
    this.AllowDrop = true;protected override void OnDragEnter(DragEventArgs drgevent)
    {
        if (drgevent.Data.GetDataPresent(DataFormats.FileDrop))
            drgevent.Effect = DragDropEffects.Copy;
        base.OnDragEnter(drgevent);
    }protected override void OnDragDrop(DragEventArgs drgevent)
    {
        if (drgevent.Data.GetDataPresent(DataFormats.FileDrop))
        {
            string[] vFileNames = (string[])drgevent.Data.GetData(
                DataFormats.FileDrop);
            Text = string.Join(",", vFileNames);
        }
        base.OnDragDrop(drgevent);
    }
      

  2.   

    不过这样的话,只能将选择的东西拖放到form窗体上才有效,
    能否拖放到form里的控件比如textbox里,同样有效呢?
      

  3.   

    参考如下代码:
    private void Form1_Load(object sender, EventArgs e)
    {
        richTextBox1.AllowDrop = true;
        richTextBox1.DragDrop += new DragEventHandler(richTextBox1_DragDrop);
        richTextBox1.DragEnter += new DragEventHandler(richTextBox1_DragEnter);
    }void richTextBox1_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
            e.Effect = DragDropEffects.Copy;
    }void richTextBox1_DragDrop(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            string[] vFileNames = (string[])e.Data.GetData(
                DataFormats.FileDrop);
            Text = string.Join(",", vFileNames);
        }
    }