求高手指导。异地窗体触发主窗体事件问题
小白我阐述一下我的问题点:点击主窗体按钮弹出一个Form2,然后在form2上点击按钮弹出form3.我想在form3上通过按钮触发主窗体form1的一个事件。如何实现。目前小弟只能做到在form2上可以触发form1的一个事件。求高手指导。代码如下Form1代码:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Form3 bc = null;
public Form1()
{
InitializeComponent();
bc = new Form3();
bc.MyEvent += new Form3.MyDelegate(writeplc);
}
private void button1_Click(object sender, EventArgs e)
{
Form2 a = new Form2();
a.ShowDialog();
}
void writeplc()
{
this.textBox1.Text += "已单击b窗体按钮\r\n";
}
}
}
Form2代码:
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 bd = new Form3();
bd.ShowDialog();
}
}
}
Form3代码:
namespace WindowsFormsApplication1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
public delegate void MyDelegate();
public event MyDelegate MyEvent;
private void button1_Click(object sender, EventArgs e)
{
if (MyEvent != null)
MyEvent();
}
}
}