C# 程式碼增加元件
阿新 • • 發佈:2021-02-02
1、程式碼新增 按鈕
Button st_1 = new Button();
st_1.Text = "asas";
this.Controls.Add(st_1);
2、程式碼繫結事件
private void button1_Click(object sender, EventArgs e) { //新增按鈕 Button st_1 = new Button(); st_1.Text = "asas"; this.Controls.Add(st_1); //新增事件 st_1.Click += new System.EventHandler(button_st_1_MouseClick); } //定義事件 private void button_st_1_MouseClick(object sender, EventArgs e) { MessageBox.Show("click"); }