Re: [問題] click問題

看板C_Sharp作者 (Naz130)時間4年前 (2019/09/15 16:04), 編輯推噓1(105)
留言6則, 2人參與, 4年前最新討論串2/2 (看更多)
※ 引述《GooLoo (平凡)》之銘言: : 請問一下, : button1內要做 按button2動作,可以如下這樣寫. : 問題來了 : 如果button1要做 button2~10動作,甚至20,30...個 : 一個一個打要很久 : button2_Click(null, null); : button3_Click(null, null); : button4_Click(null, null); : ..... : 有其他的方法嗎? : private void button1_Click(object sender, EventArgs e) : { : button2_Click(null, null); : } : private void button2_Click(object sender, EventArgs e) : { : label1.Text = "OK"; : } 用Find & PerformClick: private void Button1_Click(object sender, EventArgs e) { var parent = ((Buttn)sender).Parent; for (int i = 2; i<= 30; i++) { foreach (var control in parent.Controls.Find($"button{i}", false)) { if (control is Button) { ((Button)control).PerformClick(); } } } } private void Button2_Click(object sender, EventArgs e) { MessageBox.Show("2"); } private void Button3_Click(object sender, EventArgs e) { MessageBox.Show("3"); } private void Button4_Click(object sender, EventArgs e) { MessageBox.Show("4"); } … -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.218.26.195 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1568534641.A.053.html

09/15 16:11, 4年前 , 1F
感謝,原來find可以這樣用
09/15 16:11, 1F

09/16 07:12, 4年前 , 2F
如果不是click, 如combobox的change就沒法用了
09/16 07:12, 2F

09/16 08:51, 4年前 , 3F
ComboBox沒有叫做change的事件啊
09/16 08:51, 3F

09/18 07:20, 4年前 , 4F
抱歉,是selectedindexchanged
09/18 07:20, 4F

09/18 07:24, 4年前 , 5F
Numericupdown 的value change, 沒有performclick可以用
09/18 07:24, 5F

09/19 09:15, 4年前 , 6F
前者直接改SelectedIndex,後者直接改Value不就好了?
09/19 09:15, 6F
文章代碼(AID): #1TVV1n1J (C_Sharp)
討論串 (同標題文章)
本文引述了以下文章的的內容:
問題
7
19
完整討論串 (本文為第 2 之 2 篇):
問題
7
19
文章代碼(AID): #1TVV1n1J (C_Sharp)