C# 窗体打开拖动到窗体的文件

 1         private void Form3_DragEnter(object sender, DragEventArgs e)
 2         {
 3             if (e.Data.GetDataPresent(DataFormats.FileDrop))
 4             {
 5                 e.Effect = DragDropEffects.All;    
 6             }
 7             else
 8             {
 9                 e.Effect = DragDropEffects.None;
10             }
11 
12         }
13 
14         private void Form3_DragDrop(object sender, DragEventArgs e)
15         {
16             string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop, false);
17             if (null != filePaths && filePaths.Length > 0)
18             {
19                 foreach (string item in filePaths)
20                 {
21                     var lines = System.IO.File.ReadAllLines(item);
22                     Array.ForEach(lines.ToArray(), n => richTextBox1.AppendText(n.ToString() + "\r\n"));
23                 }
24             }
25         }

 

posted @ 2017-08-16 15:16  奔跑.Ken  阅读(285)  评论(0编辑  收藏  举报