2013-07-12 45 views
1

在表单加载上,您可以从Environment.CommandLine检索整个命令字符串。但是,当我使用应用程序事件来检测命令行字符串时,我的单个实例应用程序再次打开,我找不到相当于Environment.CommandLineStartupNextInstanceEventArgsVB.NET等效于(StartupNextInstanceEventArgs)中的Environment.CommandLine

这里是我的代码:

Private Sub MyApplication_StartupNextInstance(_ 
    ByVal sender As Object, _ 
    ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs _ 
) Handles Me.StartupNextInstance 
     'I can only use e.CommandLine which returns a readonlycollection, not a string like Environment.CommandLine does. Can someone help me out? 
     End Sub 
+0

只需使用'昏暗CMD =的string.join(””,e.CommandLine.ToArray)' –

回答

3

从MSDN My.Application.StartupNextInstance Event

必须使用e参数的的CommandLine属性来访问以后尝试的参数来启动一个实例应用。 My.Application.CommandLineArgs属性提供用于启动单实例应用程序的第一个实例的参数。

所以只需使用somethihg像:

For Each arg As String in e.CommandLine 
    Debug.WriteLine(arg) 
Next