[Solved] Can anyone help me about command line parameters in a WinForms application?


It’s actually quite simple to do.

When your application loads, get a list of the command line variables, then iterate through them and look for the one you want, then act accordingly:

Public Sub Main()
    Dim arguments As String() = Environment.GetCommandLineArgs()

    For Each a In arguments 'loop through the args in case there are multiple
        Select Case a.ToUpper 'compare in uppercase if you don't care how the user enters it.
            Case "-U"
                'the -U argument was found, set a flag, or perform an action, or otherwise act accordingly.
        End Select
    Next
End Sub

I always put it in a select case, because in my apps, I may have multiple arguments and I loop through them all and set properties accordingly. In a select case, it’s easy to add other parameters later. You can easily add a case else in the event you want to throw up an ‘invalid argument’ message.

0

solved Can anyone help me about command line parameters in a WinForms application?