我試圖通過使用像下面這樣的循環動態分配按鈕控制文本動態文本:分配按鈕通過環
int ButtonNumber = 1;
while (ButtonNumber < 10)
{
//WHAT TO DO HERE!?
ButtonNumber++;
}
我想避免以下:
button1.Text = "";
button2.Text = "";
button3.Text = "";
button4.Text = "";
button5.Text = "";
button6.Text = "";
button7.Text = "";
button8.Text = "";
button9.Text = "";
難道你還需要實例每個Button對象?也將它們添加到列表中。 – Tudor
@Tudor:是的,我假設發生在別處...... –
爲什麼不建議使用通過ID獲取控件? 它就像一個魅力!? – Birdman