日期:2014-05-20 浏览次数:21089 次
private void UserInfo_Load(object sender, EventArgs e) { LoadButton(); } #region 循环按钮事件 private void LoadButton() { Button[] btns = new Button[15]; for (int i = 0; i < 15; i++) { btns[i] = new Button(); btns[i].Location = new Point(3, 0 + i * 29);//你把所有按钮放在同一位置吗?-> btns[i].Location = new System.Drawing.Point(100,100+ i*60);// btns[i].Name = "btn" + i; btns[i].Size = new System.Drawing.Size(80, 30); btns[i].Text = i.ToString(); btns[i].Click += new EventHandler(Button_Click); this.panel1.Controls.Add(btns[i]); } } void Button_Click(object sender, EventArgs e) { Button b = (Button)sender; MessageBox.Show(b.Text); LinkLabel[] link = new LinkLabel[5]; for (int i = 0; i < 5; i++) { link[i] = new LinkLabel(); link[i].Location = new Point(71 + i * 60, 10);//你把所有按钮放在同一位置吗?-> btns[i].Location = new System.Drawing.Point(100,100+ i*60);// link[i].Name = b.Text + "link" + i.ToString(); link[i].Size = new System.Drawing.Size(50, 16); link[i].Text = b.Text + "link"+i.ToString(); link[i].Click += new EventHandler(LinkLabel_Click); this.panel2.Controls.Add(link[i]); } } void LinkLabel_Click(object sender, EventArgs e) { LinkLabel link = (LinkLabel)sender; MessageBox.Show(link.Text); } #endregion