Capture Explorer文件列表在exe上删除

时间:2013-07-26 16:20:51

标签: c# vb.net winforms

我正在VB.Net WinForms VS2010中构建一个文件工具,我想允许用户在Windows资源管理器中选择多个文件并将它们拖放到我的exe上。这甚至可能吗?

我的代码适用于打开表单上的drop。但需要弄清楚我是否可以将对象放在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

2 个答案:

答案 0 :(得分:0)

事实证明这很容易:

Private Sub frmDragDrop_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Dim sARGS As String()
    sARGS = Environment.GetCommandLineArgs()
    If sARGS.Length > 0 Then
        For Each s In sARGS
            TextBox1.AppendText(s & vbCrLf)
        Next
    End If
End Sub

并非所有args()文件,前一个或两个都是开销。

如果有人知道如何使用上面的代码调试,请告诉我!也许你能不能让VS2010将相同的args()传递给在IDE中运行的程序?

答案 1 :(得分:0)

以下是更顺畅的调试体验的快速提示:

    Sub Main()
        Dim commandLineArgs() As String

#If Not Debug Then
        commandLineArgs = Environment.GetCommandLineArgs()
#Else
        commandLineArgs = "/fake/path/for/debugging/myApp.exe".Split()
#End If

        For Each argument As String In commandLineArgs
            Console.WriteLine(argument)
        Next
    End Sub