我在VB.Net WinForms VS2010中创建一个文件工具,我想允许用户在Windows资源管理器中选择多个文件,并将它们拖放到我的exe文件中。这甚至有可能吗?捕获资源管理器文件列表上删除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
您可以:在项目设置|调试选项卡,设置“命令行参数”。 –
请注意,数组中的第一项只是您的应用程序的路径。 –