Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing args (arguments) into a window form application

I have my Windows Application that accepts args and I use this in order to set up the Window behaviour

problem is that I need to pass text in some of this arguments but my application is looking at it as multiple args, so, this:

"http://www.google.com/" contact 450 300 false "Contact Info" true "Stay Visible" true

has actually 11 arguments instead of the 9 that I am expecting.

What is the trick to get "contact info" and "stay visible" to be passed as only one argument?

like image 937
balexandre Avatar asked Nov 16 '25 13:11

balexandre


2 Answers

Are you running it directly from the command line? If so, I'd expect that to work just fine. (I assume you're using the parameters from the Main method, by the way?)

For instance, here's a small test app:

using System;

class Test
{
    static void Main(string[] args)
    {
        foreach (string arg in args)
        {
            Console.WriteLine(arg);
        }
    }
}

Execution:

>test.exe first "second arg" third
first
second arg
third

This is a console app, but there's no difference between that and WinForms in terms of what gets passed to the Main method.

like image 69
Jon Skeet Avatar answered Nov 19 '25 02:11

Jon Skeet


MSDN says, that it should work the way you mentioned.

class CommandLine
{
    static void Main(string[] args)
    {
        // The Length property provides the number of array elements
        System.Console.WriteLine("parameter count = {0}", args.Length);

        for (int i = 0; i < args.Length; i++)
        {
            System.Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
        }
    }
}
like image 32
Xn0vv3r Avatar answered Nov 19 '25 02:11

Xn0vv3r



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!