VB 如何获取拖放到按钮上的图像的文件路径

How to get the filepath of an image dropped onto a button in VB

我正在尝试获取拖放到 VB 按钮上的图像的文件路径。我已将按钮设置为允许放下,并且已将此段设置为保存事件代码:

Private Sub btnDropZone_drop(sender As Object, e As EventArgs) Handles btnDropZone.DragDrop

    End Sub

我将如何从这个事件中获取文件路径作为字符串?提前致谢!

按钮是一个非常小的放置目标,但它的工作方式与其他任何东西一样:检查 e As DragEventArgs:

Private Sub btnDropZone_drop(sender As Object, 
      e As EventArgs) Handles btnDropZone.DragDrop

    'ToDo check the format to see what was dropped
    Dim Files As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())

    For Each s As String In Files
        ListBox1.Items.Add(Path.GetFileName(s))
    Next
End Sub

当您试图弄清楚在某个事件中要做什么时,请务必查看事件参数的含义和内容