您的位置:首页 > 其它

动态创建的按钮 以及 他们的事件

2008-06-02 10:06 127 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: