找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4275|回复: 0

VB.net – 拖放并获取文件路径

[复制链接]

481

主题

49

回帖

7300

积分

管理员

积分
7300
发表于 2020-8-11 13:01:46 | 显示全部楼层 |阅读模式
通过将 AllowDrop属性设置为True并处理 DragEnter和 DragDrop事件,才能启用drap-and-drop.
在DragEnter事件处理程序中,您可以检查数据是否是要使用DataFormats类的类型.

在DragDrop事件处理程序中,使用DataEventArgs的Data属性来接收实际数据.

例:

Private Sub Form1_Load(sender As System.Object,e As System.EventArgs) Handles MyBase.Load

    Me.AllowDrop = True

End Sub

Private Sub Form1_DragDrop(sender As System.Object,e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop

    Dim files() As String = e.Data.GetData(DataFormats.FileDrop)

    For Each path In files

        MsgBox(path)

    Next

End Sub

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

    If e.Data.GetDataPresent(DataFormats.FileDrop) Then

        e.Effect = DragDropEffects.Copy

    End If

End Sub

QQ|手机版|小黑屋|爱淘机 ( 鲁ICP备2022040313号-4 )

GMT+8, 2025-7-6 09:36 , Processed in 0.135624 second(s), 24 queries .

Powered by 爱淘机 X3.5

© 2001-2025 爱淘机.

快速回复 返回顶部 返回列表