[VB.Net]讀取拖曳檔案的路徑

轉貼文章:六度空間 http://jeremy.tfeng.org/?p=502
此程式碼可讀取到使用者拖曳到視窗裡的檔案路徑

請開啟一個Windows Form 後,分別在以下事件加入程式碼:
(Form1_Load,Form1_DragDrop,Form1_DragEnter)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.AllowDrop = True
   End Sub

   Private Sub Form1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop
       Dim DragFilePath As String = CType(e.Data.GetData("FileNameW"), Array).GetValue(0)
       MsgBox(DragFilePath)
   End Sub

   Private Sub Form1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter
       e.Effect = DragDropEffects.All
   End Sub

   Private Sub Form1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter

       e.Effect = DragDropEffects.All

   End Sub

留言

這個網誌中的熱門文章

[Excel]將圖片放置於儲存格中

[軟體]AUTOCAD關於開啟圖面時,字型找不到,而要手動指定成 chineset.shx 字型檔問題

[MS SQL]查詢資料庫中每個資料表之列數與資料表大小(容量)資訊。Get size of all tables in database