我想做一个Form 上面有个textbox ,需要拖动效果,如果鼠标拖住外部的(程序以外的)的文件,拉到我的Form ,然后再textbox就会显示该文件的路径?
请问怎么实现?是不是 需要写一个外壳扩展?还是不用

解决方案 »

  1.   

    http://topic.csdn.net/u/20100107/00/553230c3-8d6a-47c5-98a5-fda4df0334c1.html
      

  2.   

     private void Form1_Load(object sender, EventArgs e)
            {
                textBox1.AllowDrop = true;
                textBox1.DragEnter += new DragEventHandler(textBox1_DragEnter);
                textBox1.DragDrop += new DragEventHandler(textBox1_DragDrop);         }
            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)
            //{
            //    string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            //    string s = "";        //    foreach (string File in FileList)
            //        s = s + " " + File;
            //    textBox1.Text = s;
            //}
            //private void textBox1_DragEnter(object sender, DragEventArgs e)
            //{
            //    if (e.Data.GetDataPresent(DataFormats.FileDrop))
            //    {
            //        e.Effect = DragDropEffects.Copy;
            //    }
            //}        private void textBox1_DragDrop(object sender, DragEventArgs e)
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
                    textBox1.Lines = fileNames;
                }
            } 
      

  3.   

    拖放文件到窗体,获取文件路径http://blog.csdn.net/wangwenzhuang/archive/2010/10/31/5978087.aspx
      

  4.   

    结贴原来直接拿就有的,我还以为要写个shell扩展才能呢