2009-01-21 41 views
3

我有一個接受ARGS我的Windows應用程序,我爲了建立窗口行爲傳遞ARGS(參數)到窗口申請表格

問題,請使用這是我需要通過文本中的一些這個論點但我的應用程序是看着它作爲多個指定參數時,那麼,這樣的:

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

實際上有參數,而不是在,我期待。

什麼手段來得到「聯繫信息」「看得到」因爲只有一個參數傳遞?

回答

6

你是直接從命令行運行它嗎?如果是這樣,我希望能夠正常工作。 (我假設你正在使用的參數從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之間沒有區別。

+0

約翰那是欺騙......讓在第一:-)但只給一半回答第一次:-) – 2009-01-21 11:14:36

2

MSDN says,它應該按照你提到的方式工作。

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

你是如何執行你的應用程序?
如果你從你可能已經忘記了正確格式化參數字符串另一個應用程序執行:

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