將一個文件拖拽到窗體的某個控件時,將該控件的路徑顯示在該控件上,只要拿到了路徑天然能夠讀取文件中的內容了windows
將一個控件的屬性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(); }
private void button1_Click(object sender, EventArgs e) { // System.Diagnostics.Process.Start("Explorer.exe", "c:\\windows"); System.Diagnostics.Process.Start("Explorer.exe", this.button1.Text); }