当前位置: 代码迷 >> 综合 >> 文件流操作(12)——WinForm开发(34)——C#之winform实现文件拖拽功能
  详细解决方案

文件流操作(12)——WinForm开发(34)——C#之winform实现文件拖拽功能

热度:25   发布时间:2023-10-01 16:39:07.0

将一个文件拖拽到窗体的某个控件上时,将该文件的路径显示在该控件上,只要拿到了路径自然可以读取文件中的内容了。将这个控件的属性AllowDrop设置为true,然后添加DragDrop、DragEnter事件处理函数,代码如下:

        private void TextBox1_DragDrop(object sender, DragEventArgs e){textBox1.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();}private void TextBox1_DragEnter(object sender, DragEventArgs e){if (e.Data.GetDataPresent(DataFormats.FileDrop)){e.Effect = DragDropEffects.Link;}else{e.Effect = DragDropEffects.None;}}

 

  相关解决方案