private void btn_addButtons_Click(object sender, System.EventArgs e)
{
// 计数,计算目前是添加的几个按钮
count++;
// 计算待添加按钮的位置
int localY = this.btn_addButtons.Height * count;
int localX = 10 * count;
Button toAddButton = new Button();
// 设置待添加按钮的属性
toAddButton.Name="Button " + count;
toAddButton.Text=" 按钮" + count + " ";
toAddButton.Location= new Point(localX, localY);
// 设置待添加按钮的事件
toAddButton.MouseEnter += new System.EventHandler(this.btn_MouseEnter);
toAddButton.MouseLeave += new System.EventHandler(this.btn_MouseLeave);
toAddButton.Click += new System.EventHandler(this.btn_Click);
// 把控件添加到窗口中
this.Controls.Add(toAddButton);
}`这里写代码片`
C# 按钮添加事件
最新推荐文章于 2024-07-13 20:22:50 发布