2011-11-23 59 views
0

我有一個窗體窗體,我想從命令行的不同選項卡頁面上啓動。 這是因爲表單可以由用戶指定的日期/時間 由時間/ cron服務啓動。窗體窗體選項卡式頁面:從命令行在不同選項卡上啓動窗體

如何獲取表單應用程序上下文以轉到非默認第一個選項卡?

[STAThread] 
    static void Main (string[] args) 
    { 
     Debug.WriteLine("Environment Args= {0}", args.Count()); 
     for (int i=0; i < args.Count(); i++) 
     { 
      Debug.WriteLine(String.Format("{0}:{1}", i, args[i])); 
     } 
     Application.EnableVisualStyles(); 
     Application.SetCompatibleTextRenderingDefault(false); 
     Form myForm = new DailyDirectories(); 
     if (args.Count() > 0) 
     { 
      Application.Run(myForm.???); 
     } 
    } 

回答

0

您可以嘗試到參數傳遞給你的窗體類甚至設置屬性

Form myForm = null; 
if (args.Count() > 0) 
{ 
    // in case args[0] contains the start index for your tabControl 
    int tabStartIndex = int.Parse(args[0]); 
    myForm = new DailyDirectories(tabStartIndex);   
    Application.Run(myForm); 
} else // e.g. start form without index 

在您的表單類中,您必須添加/更改源代碼。

class DailyDirectories ... 
{ 
    /// add constructor or change default constructor 
    pubic DailyDirectories(int tabStartIndex) 
    { 
     InitializeComponents(); 
     this.tabControl.SelectedIndex = tabStartIndex; 
    } 

} 
+0

尊敬的弗朗茨先生; –

+0

測試過,效果!看起來有點棘手得到一個標籤頁的索引。它與Tab索引不同,製作可見,主動不是實現它的方式。排序似乎取決於它是如何創建的,而不是現在您想要將選項卡排序給用戶。最終,我想重新洗牌標籤,使其作爲左邊第一個標籤。感謝您的見解。 –

+0

無需運行或初始化參數。環境在任何地方都可見。我喜歡加載屬性。瞭解事件如何滲透代碼意味着你不需要編寫太多的代碼。 –

0

既然你在談論的標籤,我想你有一個TabControl,那麼你爲什麼不設置標籤頁,你想在你的窗體的Load()事件?

private void Form_Load(object sender, EventArgs e) 
{ 
    this.tabControl.SelectedIndex = YourIndex; 
} 
相關問題