we use delegate method as event
first we declared a delegate
public delegate void Mydelegate(string a)
then we write the instance of this type
public Mydelegate _myDelegate;
then we can use it;
Program.cs
Application.Run(new Form3());
Form3.cs
Form2 frm2;
public Form3()
{
InitializeComponent();
frm2 = Form2.Instance();
if (frm2._FrmMyDelegateString == null)
frm2._FrmMyDelegateString += fillText;
}
private void fillText(string str)
{
this.textBox1.Text = str;
}
private void button1_Click(object sender, EventArgs e)
{
frm2.Show();
}
Form2.cs
private Form2()
{
InitializeComponent();
myFrm = Form1.Instance();
}
private static Form2 frm2;
public static Form2 Instance()
{
if (frm2 == null)
frm2 = new Form2();
return frm2;
}
Form1 myFrm;
public MyDelegateString _FrmMyDelegateString;
private void button1_Click(object sender, EventArgs e)
{
if (myFrm._myDelegateString == null)
myFrm._myDelegateString += _FrmMyDelegateString;
Form1 myfrm1 = Form1.Instance();
myfrm1.Show();
}
Form1.cs
as the resouces
private Form1()
{
InitializeComponent();
}
private static Form1 frm;
public static Form1 Instance()
{
if (frm == null)
frm = new Form1();
return frm;
}
public MyDelegateString _myDelegateString;
private void button1_Click(object sender, EventArgs e)
{
if (_myDelegateString != null)
_myDelegateString("Proxy Event");
}