[問題] 動態產生button並傳值問題
在c#裡面我動態產生按鈕 並讓按鈕可以有對應動作
google到的方法是下面這樣
Button oButton = new Button();
this.Controls.Add(oButton);
oButton.Click += new System.EventHandler(this.button_Click);
所以我要先寫一產生一個方法類似
private void button_Click(object sender, EventArgs e){
....
}
這樣才能呼叫此按鈕方法,那我的問題是button可不可以傳值阿~
如果不能傳值整個button click方法不是就寫死了嗎@@
舉個例
private void button_Click(object sender, EventArgs e){
接收變數並assign給 file_temp,然後執行下面的語法
XmlTextReader reader = new XmlTextReader(file_temp);
//使用不同按鈕可以對不同檔名XML進行讀取
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.134.26.22
→
05/16 20:05, , 1F
05/16 20:05, 1F
→
05/16 20:19, , 2F
05/16 20:19, 2F
→
05/16 22:55, , 3F
05/16 22:55, 3F
→
05/16 22:55, , 4F
05/16 22:55, 4F
→
05/17 06:30, , 5F
05/17 06:30, 5F
→
05/17 09:56, , 6F
05/17 09:56, 6F