vb.net 将参数传递给 Windows 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18216524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:38:56  来源:igfitidea点击:

Passing argument to windows application

vb.netwinforms

提问by Pinu

I need to be able to pass an argument to my windows application so that I can run the code based on the argument passed:

我需要能够将参数传递给我的 Windows 应用程序,以便我可以根据传递的参数运行代码:

Below is the function that is called when the windows application start running:I need this method to have arguments.

下面是windows应用程序开始运行时调用的函数:我需要这个方法有参数。

Private Sub Start_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Try
        Dim Mgr As New StartMgr
        Mgr.Import()  // from here controls goes to a class library and it the whole //code, I need this function Import(arg) so that it can run partial code based on args

        Me.Visible = False
        Me.Close()
    Catch ex As Exception

    Finally
        Application.Exit()
    End Try

    End Sub

回答by the_lotus

If you mean command line argument, I don't think there's much you can do unless you add a property to your class. But you can always access the args through this function Environment.GetCommandLineArgs().

如果您的意思是命令行参数,我认为除非您向类添加属性,否则您无能为力。但是您始终可以通过此函数Environment.GetCommandLineArgs()访问参数。

回答by Jean Paul Beard

Fácil podéis usar esto

Fácil podéis usar esto

Dim args As String() = Environment.GetCommandLineArgs()
TextBox1.Text = String.Join(".", args)