将一个文件拖拽到窗体的某个控件时,将该控件的路径显示在该控件上,只要拿到了路径自然可以读取文件中的内容了

将一个控件的属性AllowDrop设置为true,然后添加DragDrop、DragEnter时间处理函数,如下:

 

private void txtAppPath_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Link; } else { e.Effect = DragDropEffects.None; } } private void txtAppPath_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { txtLocalFileName.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); }

 

相关文章:

  • 2021-11-05
  • 2022-12-23
  • 2021-09-08
  • 2021-08-17
  • 2022-12-23
  • 2021-12-22
  • 2021-10-14
猜你喜欢
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案