从桌面,或者任意地方,拖个文件到自己的Form中,
Form中有个textBox拖进去 鼠标松开  textBox 就显示拖入文件的路径

解决方案 »

  1.   

    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)
    {
        if(e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            string filename= ((System.Array)e.Data.GetData(DataFormasts.FileDrop)).GetValue(0).ToString();
            ...
        }
    }
      

  2.   

               IDataObject iData = Clipboard.GetDataObject();
               string[] str;
               if (iData!=null)
               {
                bool bol = iData.GetDataPresent(DataFormats.FileDrop);
               str = (String[])iData.GetData(DataFormats.Text);
               if(File.Exists(str[0])||Directory.Exists(str[0]))
               {
                   textBox.Text=str[0].ToString();
                   }
      

  3.   

    我是WPF里的
    DataFormats.FIleDrop这个点不出来
      

  4.   

    哦,我看错了。是没有textBox1_DragDrop 这个
      

  5.   

    WPF不熟,应该有类似的事件,看看http://syxc.javaeye.com/blog/719183能不能解决
      

  6.   

    WPF 哈哈,想着赶快给分啊,要不下回不告诉你了 ^_^     
    /// <summary>
            /// 拖拽添加文件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void LtbFiles_Drop(object sender, DragEventArgs e)
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    var vFileNames = (string[])e.Data.GetData(DataFormats.FileDrop);                var dic = FileAddUtil.AddFiles(vFileNames);                textBox1.Text = dic[0];
                }
            }        private void LtbFiles_DragEnter(object sender, DragEventArgs e)
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    e.Effects = DragDropEffects.Link;
                }
            }
      

  7.   

    IDataObject data = Clipboard.GetDataObject();
    string[] formats = data.GetFormats();foreach (string format in formats)
      Console.WriteLine(format);
    这样遍历