C# 文件拖放到此程序的操作

   问题描述:

怎么写代码可以实现指定类型的文件通过鼠标拖放显示在程序的文本框中,如:选中3个文件(3个文件的格式有MP3和wma)拖到程序,程序的文本框显示这三个文件的路径...

解决代码:

this.textBox1.AllowDrop = true;
this.textBox1.Multiline = true;

 private void textBox1_DragDrop(object sender, DragEventArgs e)
        {
            Array aryFiles = ((System.Array)e.Data.GetData(DataFormats.FileDrop));
            for(int i = 0;i<aryFiles.Length;i++)
            {
                this.textBox1.AppendText(aryFiles.GetValue(i).ToString() + Environment.NewLine);
            }
        }

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

 

 
posted @ 2014-10-21 09:54  kevin_cnblogs  阅读(701)  评论(0编辑  收藏  举报