private void btnAdd_Click ( object sender , System.EventArgs e )
{
//按钮数量计算器在每次按钮按动后加“1”
counter += 1 ;
//对要产生的按钮的纵坐标的相对位置是前一个产生按钮的相对位置的纵坐标加“3“
locY += this.btnAdd.Height + 3 ;
//创建一个新的Button组件
Button myButton = new Button ( ) ;
//设定他的名称和Text属性,以及产生的位置
myButton.Name = "Button " + counter ;
myButton.Text = "按钮 " + counter ;
myButton.Location = new Point ( btnAdd.Location.X , locY ) ;
//为产生的新的Button组件设定事件,本文中为产生的按钮设定了三个事件
myButton.MouseEnter += new System.EventHandler ( this.btn_MouseEnter ) ;
myButton.MouseLeave += new System.EventHandler ( this.btn_MouseLeave ) ;
myButton.Click += new System.EventHandler ( this.btn_Click ) ;
//在窗体中显示此按钮
this.Controls.Add ( myButton ) ;
}
有个毛病就是当你来回加载与卸载动态时界面刷新不及时,即控件实际上被卸载了,但界面上还有其“影子”
浙公网安备 33010602011771号