我在我的win應用程序中有2個按鈕。當我點擊c中的另一個按鈕時如何調用按鈕點擊事件#
Button1的做一個任務:
private void button1_Click(object sender, EventArgs e)
{
progressBar1.Value = 0;
String[] a = textBox7.Text.Split('#');
progressBar1.Maximum = a.Length;
for (var i = 0; i <= a.GetUpperBound(0); i++)
{
ansh.Close();
progressBar1.Value++;
}
}
按鈕2做以下
private void button2_Click(object sender, EventArgs e)
{
foreach (string item in listBox2.Items)
textBox7.Text += item.Contains("@") ? string.Format("{0}#", item.Split('@')[0]) : string.Empty;
}
我只是想只使用一個按鈕兩個事件。
但我想在按鈕1調用的事件之前調用button2的事件。
意思是我想用一個按鈕代替按鈕1和2,當我點擊我想要做的第一件事就是在文本框中獲取列表框項目。
{
foreach (string item in listBox2.Items)
textBox7.Text += item.Contains("@") ? string.Format("{0}#", item.Split('@')[0]) : string.Empty;
}
然後事件開始進度條和關閉連接x。
progressBar1.Value = 0;
String[] a = textBox7.Text.Split('#');
progressBar1.Maximum = a.Length;
for (var i = 0; i <= a.GetUpperBound(0); i++)
{
ansh.Close();
progressBar1.Value++;
}
一個很好的解決方案將被提取功能集成到方法,並調用裏面的方法按鈕處理程序。這樣你就不需要點擊click事件,而是調用一個方法。維護也很容易。 – pasty
@pasty非常感謝你 –