求助vb.net拖拽文件到窗体获取文件信息
有一个窗体Form1我想实现拖拽一个图标到这个窗体里面之后返回那个文件的信息如路径返回的位置可以是窗体print可以是textBox也可以label也可以Msg这无所谓谢...
有一个窗体Form1我想实现拖拽一个图标到这个窗体里面之后返回那个文件的信息 如路径返回的位置可以是窗体print 可以是textBox 也可以label 也可以Msg 这无所谓谢谢 帮忙指点下 我一点思路都没有
展开
展开全部
这是一个简单的示例,你只需要新建一个项目,并在项目上放置一个文本框:TEXTBOX1,然后,将以下代码复制到代码区:
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_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
Try
If e.Data.GetDataPresent(DataFormats.FileDrop) = True Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Form1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
Try
Dim filepaht As String() = e.Data.GetData(DataFormats.FileDrop)
For Each File As String In filepaht
textBox1.Text = File
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
如此,在文本框里将会出现被拖曳文件的路径信息。
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_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
Try
If e.Data.GetDataPresent(DataFormats.FileDrop) = True Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Form1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
Try
Dim filepaht As String() = e.Data.GetData(DataFormats.FileDrop)
For Each File As String In filepaht
textBox1.Text = File
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
如此,在文本框里将会出现被拖曳文件的路径信息。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询