我正在 VB.Net WinForms VS2010 中构建一个文件工具,我希望允许用户在 Windows 资源管理器中选择多个文件并将它们拖放到我的 exe 上。这甚至可能吗?
我有代码可以在打开的表单上放置。但需要弄清楚我是否可以将对象放在 EXE 上。
Private Sub frmDragDrop_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Dim returnValue As String()
    returnValue = Environment.GetCommandLineArgs()
    If returnValue.Length > 1 Then
        MessageBox.Show(returnValue(1).ToString()) ' just shows first file from WE
    Else
        MessageBox.Show("Nothing")
    End If
End Sub
这可以正常工作(不是完整的示例,需要表单上的其他设置):
Private Sub ListBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstFromList.DragDrop
    If e.Data.GetDataPresent(DataFormats.FileDrop) Then
        Dim MyFiles() As String
        Dim i As Integer
        ' Assign the files to an array.
        MyFiles = e.Data.GetData(DataFormats.FileDrop)
        ' Loop through the array and add the files to the list.
        For i = 0 To MyFiles.Length - 1
            If IO.Directory.Exists(MyFiles(i)) Then
                MyFiles(i) &= " <DIR>"
            End If
            lstFromList.Items.Add(MyFiles(i))
        Next
        RefeshCounts()
    End If
End Sub