C#中實作檔案拖放打開的方法
設定Form屬性 AllowDrop = True;
在Form事件中
private void Form1_DragDrop(object sender, DragEventArgs e) { string localFilePath = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();//檔案完整路徑 string extension = System.IO.Path.GetExtension(localFilePath);//檔案后綴名 if (extension == ".cbd") { //todo you code } } private void Form1_DragEnter(object sender, DragEventArgs e) { string localFilePath = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); string extension = System.IO.Path.GetExtension(localFilePath); if (string.Compare(extension, ".cds", true) == 0) { e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.None; } }
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/67170.html
標籤:C#
下一篇:The finally block does not always execute in try finally
