2011-06-19 33 views
1

我有一個包含無限數量的用戶和添加選項的窗體。 有些選項位於文本框中,有些位於組合框中(選定的是要提取的值)。如何從控件提取值並將其寫入XML?

表單以一種方式讓用戶可以添加他想要的組合框和文本框,並讓他將這些信息寫入XML。

如何在c#中編寫代碼?如果任何人都可以給我一個簡短的例子,其中每個添加組合框和文本框都會循環顯示,那就太棒了。

預先感謝您。

+0

這不會讓用戶有無限的時間嗎? ;) – TrueWill

回答

2

您可以像這樣遍歷表單中的所有控件。

foreach(Control control in this.Controls) 
{ 
    //here 'this' is representing the form you want to iterate through 

    //you can check whether it is a combobox or a text box 
    if(control.GetType() == typeof(Combobox)) 
    { 
     //this is a combo box 
    } 
    else if(control.GetType() == typeof(Textbox)) 
    { 
     //this is a text box 
    } 
} 

使用上面的方法,您會發現特定窗體中的控件。之後,您可以在XML文件中寫入信息

相關問題