如何在VB.net中拖动文件并获取它的路径 [英] how to drag a file and get path of it in VB.net
本文介绍了如何在VB.net中拖动文件并获取它的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Winform中实现Panel,当用户在其上拖动文件(一个简单的.txt文件)时,它应该接受它并将其路径存储到一个名为filepathname等的变量中,这个变量可以在之前使用。我可以找到有关如何实现拖放的示例,但不能找到如何获取路径并将其存储以供稍后在程序中使用的示例。使用:Visual Studio 2008 - Vb.net
谢谢!
How to implement a Panel in Winform , when a user drags a file on it (a simple .txt file) , it should accept it and stores its path into some variable called filepathname etc. which can be used earlier. I could find examples on how to implement drag and drop but not on how to get the path and store it for use later in the program. Using : Visual Studio 2008 - Vb.net
Thanks!
推荐答案
由我翻阅解决一些网站。我不知道为什么我不能早点找到它们!
Solved by me looking up through some sites. I dont know why i couldn't find them earlier!
Private Sub dropdpanel_DragEnter(sender As Object, e As DragEventArgs) Handles dropdpanel.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
End Sub
Private Sub dropdpanel_DragDrop(sender As Object, e As DragEventArgs) Handles dropdpanel.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim MyFiles() As String
' Assign the files to an array.
MyFiles = e.Data.GetData(DataFormats.FileDrop)
'If there are more than one file, set first only
'If you want another restrictment, please edit this.
filepathname = MyFiles(0)
End If
End Sub
这篇关于如何在VB.net中拖动文件并获取它的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文