public partial class Form1 : Form
{
Button myButton = new Button();
public Form1()
{
InitializeComponent();
///
this.Controls.Add(myButton) ;
myButton.Name = "btn";
//设定他的名称和Text属性,以及产生的相对位置
myButton.Name = "Button " ;
myButton.Text = "按钮 " ;
myButton.Location = new Point(button1.Location.X, 10);
myButton.MouseEnter += new System.EventHandler(this.btn_MouseEnter);
button1.Click += new System.EventHandler(this.btn_Click);
}
public void btn_Click(object sender, System.EventArgs e)
{
Button current = (Button)sender;
current.BackColor = Color.Red;
this.textBox1.SelectedText = current.Name;
}
public void btn_MouseEnter(object sender, System.EventArgs e)
{
Button current = (Button )sender ;
current.BackColor = Color.Red;
}