2013-07-26 54 views
0

我在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 

回答

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中运行的程序?

+0

您可以:在项目设置|调试选项卡,设置“命令行参数”。 –

+0

请注意,数组中的第一项只是您的应用程序的路径。 –

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 
相关问题