private void button1_Click(object sender, EventArgs e)
{
string a = textBox1.Text;
int h = Convert.ToInt32(a);
for (int i = 0; i <= h; i++)
{
buttonArray[i] = new Button();
buttonArray[i].Size = new Size(60, 23);
buttonArray[i].Location = new Point(40,20);
panel1.Controls.Add(buttonArray[i]);
}
}
我的任務是如果用戶在文本框中輸入3。 3個按鈕應該動態創建並添加到面板如何做到這一點?我使用的按鈕陣列,請建議我在面板上動態添加按鈕和按鈕對象
你的結果是什麼? – doge
哪種類型的面板? – progpow
你的代碼實際上工作的唯一問題是位置,每個按鈕總是相同的,試試這個buttonArray [i] .Location = new Point(40,20+(i * 20)); – Sam