将参数(参数)传递给窗体表单应用程序

我有我的Windows应用程序接受参数,我用它来设置窗口的行为

问题是我需要传递一些参数中的文本,但我的应用程序将其视为多个参数,所以,这是:

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

实际上有11个参数,而不是我所期望的9 参数。

获取“联系信息”“保持可见”只作为一个parameter passing的诀窍是什么?

你是直接从命令行运行吗? 如果是这样,我希望能够工作得很好。 (顺便说一句,我假设你使用Main方法的参数)

例如,这里有一个小测试应用程序:

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

执行:

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

这是一个控制台应用程序,但是就传递给Main方法的内容而言,它和WinForms没有区别。

MSDN说 ,它应该按照你提到的方式工作。

 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]); } } } 

你如何执行你的应用程序?
如果从另一个应用程序执行它,则可能忘记正确地格式化参数字符串:

 String arguments = "First \"Sec ond\" Third Fourth \"Fi fth\"" 

将有五个参数,而

 String arguments = "First Sec ond Third Fourth Fi fth" 

会有七个。

如果参数在快捷方式目标属性中,则同样适用:

 "C:\My Path\MyApplication.exe" "Argument 1" Argument2 Argument3 "Argument 4" 

代替

 "C:\My Path\MyApplication.exe" Argument 1 Argument2 Argument3 Argument 4