按钮的生成代码如下
for(int cnt=0;cnt<i;cnt++)
{
   newButton = new Button();
   newButton.Text = menuText;
   newButton.Location = new System.Drawing.Point(locX,locY);
   locY += 23;
   this.Controls.Add(newButton);
}
我怎么来为这些按钮写点击事件代码呢?

解决方案 »

  1.   

    newButton.Click += 你的事件处理代码
    += 出来的时候.net会自动给你生成一个方法连按两下Tab键
      

  2.   

    添加一个委托。for(int cnt=0;cnt <i;cnt++) 

      newButton = new Button(); 
      newButton.Text = menuText; 
      newButton.Location = new System.Drawing.Point(locX,locY); 
      locY += 23; 
      this.Controls.Add(newButton); 
      newButton.Click +=new EventHandler(newButton_Click);
    } 然后newButton_Click方法里面就是你点击按钮要做的是。
    private ovid newButton_Click(object sender,System.EventArgs e)
    {
    }