How do I pass command-line arguments to a WinForms application? Ask Question

How do I pass command-line arguments to a WinForms application? Ask Question

I have two different WinForms applications, AppA & AppB. Both are running .NET 2.0.

In AppA I want to open AppB, but I need to pass command-line arguments to it. How do I consume the arguments that I pass in the command line?

This is my current main method in AppB, but I don't think you can change this?

  static void main()
  {
  }

ベストアンサー1

The best way to work with args for your winforms app is to use

string[] args = Environment.GetCommandLineArgs();

You can probably couple this with the use of an enum to solidify the use of the array througout your code base.

"And you can use this anywhere in your application, you aren’t just restricted to using it in the main() method like in a console application."

Found at:HERE

おすすめ記事