怎么操作代码创建的控件?
使用代码创建的控件,要怎么对创建的控件进行操作?比如我将一个控件在代码创建时的enabled设为false,现在想通过另一个按钮的点击来使这个控件有效,要怎么做?
private void Form1_Load(object sender, EventArgs e) { FlowLayoutPanel flp = new FlowLayoutPanel(); flp.Width = 330; flp.Dock = DockStyle.Left; for (int i = 0; i < 9;i++ ) { Button but = new Button(); but.Height =but.Width= 100; but.Name = "button" + i.ToString(); but.Enabled = false; but.Click += new EventHandler(but_Click); flp.Controls.Add(but); } this.Controls.Add(flp); this.Width = 410; this.Height = 360; }这是我想修改状态的代码,不知道为什么不行
private void 开始游戏ToolStripMenuItem_Click(object sender, EventArgs e) { foreach (Control ctr in this.Controls) { if (ctr is Button) { label1.Text = (++i).ToString(); ctr.Enabled = true; } } }