0

I know, how i can passing parameters in console app but i don't know, how i can do it in form app.

Example of passing parameters in console app:
My parameters: run ConsoleApp.exe HelloWorld

static void Main(string args)
    {
    MessageBox.Show(args);
    }

I already tried this but, it keep coming up with error:

public Test(string args)
        {
            InitializeComponent();
            MessageBox.Show(args);
        }

My code:

public partial class test : Form
public test(string args)
        {
            InitializeComponent();
            MessageBox.Show(args);

        }
private void test_Load(object sender, EventArgs e)
        {
        }
Mercenary
  • 9
  • 1
  • Did you read the error message? – SLaks May 02 '19 at 20:13
  • 2
    `args` is a string array, not a string. – Robert Harvey May 02 '19 at 20:15
  • 1
    [`GetCommandLineArgs`](https://learn.microsoft.com/en-us/dotnet/api/system.environment.getcommandlineargs?redirectedfrom=MSDN&view=netframework-4.8#System_Environment_GetCommandLineArgs) as found [here](https://stackoverflow.com/questions/1179532/how-do-i-pass-command-line-arguments-to-a-winforms-application)? There seem to be quite a few results when searching with for `command line arguments in windows forms c#`. – HABO May 02 '19 at 20:17

1 Answers1

0

You need to put parameters in Main(), just like a console app.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • I know, what i did wrong. i tried and add above code to Form1.cs file instead of Program.cs This is the reason of it keep coming up with error. Thanks for help guys – Mercenary May 02 '19 at 20:40