0
我想從多個表單(Main,Two和Three)獲取所有控件,並且 比較控件標記是否等於變量str_name,如果爲true,則在c中寫入str_value的 值。文本。從csharp獲取多個表單的所有控件
代碼:
private static Form[] getformular()
{
Main main = new Main();
Two f2 = new Two();
Three f3 = new Three();
Form[] form = { main, f2, f3};
return form;
}
private void initcontrol()
{
String str_name = "name";
String str_value = "value";
foreach(Form f in getformular())
{
foreach (Control c in f.Controls)
{
if (f != null && c = null)
{
if (c.Tag.Equals(str_name))
{
c.Text = str_value;
}
}
}
}
}
能否請人幫我嗎?
我強烈建議仔細看看數據綁定,因此您不需要爲此目的重新發明輪子。 – Robert
你能解釋一下你爲什麼要這樣做,爲什麼你不能直接命名你的TextBox,比如'nameTextBox'並直接獲取它? –
更好的是,如果你想在每個文本框中使用默認值,就把它放在設計器中。 – DonBoitnott