问题描述:

怎么写代码可以实现指定类型的文件通过鼠标拖放显示在程序的文本框中,如:选中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;
        }

 

 

相关文章:

  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2021-10-16
  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-10
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2021-06-26
  • 2021-12-17
相关资源
相似解决方案