c# 可以再按button1得时候调用from2的button2_click事件吗
用委托吧
在form2中 打开form1 窗体 点击 form1的button1 调用 button2_click事件
form1中代码如下
public delegate void OnButton1Click(object sender, EventArgs e);
public event OnButton1Click OnButtonClickEvent;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
OnButtonClickEvent(null, null);
}
form2中代码如下:
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
Form1 f1 = new Form1();
f1.OnButtonClickEvent += new Form1.OnButton1Click(button2_Click);
f1.Show();
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("调用Button2");
}
亲测可用!