我如何通过命令行参数来WinForms应用程序? [英] How do I pass command-line arguments to a WinForms application?

查看:101
本文介绍了我如何通过命令行参数来WinForms应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的WinForms应用程序,APPA&安培; APPB。两者都运行.NET 2.0。

在APPA我想开APPB,但我需要命令行参数传递给它。我怎么消费,我通过在命令行参数?

这是我的APPB目前的主要方法,但我不认为你可以改变呢?

 静态无效的主要()
  {
  }


解决方案

 静态无效的主要(字串[] args)
{
  //对于这个例子的目的,我们只是打印参数到控制台。
  的for(int i = 0; I< args.Length;我++){
    Console.WriteLine(ARGS [{0}] == {1},我,ARGS [I]);
  }
}

然后参数将被存储在 ARGS 字符串数组中:

  $ AppB.exe firstArg secondArg thirdArg
ARGS [0] == firstArg
ARGS [1] == secondArg
ARGS [2] == thirdArg

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()
  {
  }

解决方案

static void Main(string[] args)
{
  // For the sake of this example, we're just printing the arguments to the console.
  for (int i = 0; i < args.Length; i++) {
    Console.WriteLine("args[{0}] == {1}", i, args[i]);
  }
}

The arguments will then be stored in the args string array:

$ AppB.exe firstArg secondArg thirdArg
args[0] == firstArg
args[1] == secondArg
args[2] == thirdArg

这篇关于我如何通过命令行参数来WinForms应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆