// event is propagated c3 => c2 => c1 => winform
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EventPropagate
{
public partial class Form1 : Form
{
c1 cc1 = new c1();
public Form1()
{
InitializeComponent();
cc1.evtcc1 += new ff( test );
}
private void button1_Click( object sender , EventArgs e )
{
cc1.fire();
}
void test( int input )
{
label1.Text = input.ToString();
}
}
public class c1
{
c2 cc2 = new c2();
public void fire() { cc2.fire(); }
public event ff evtcc1
{
add
{
Debug.WriteLine("c1");
cc2.evtcc2 += value;
}
remove { }
}
}
public class c2
{
c3 cc3 = new c3();
public void fire() { cc3.fire(); }
public event ff evtcc2
{
add
{
Debug.WriteLine("c2");
cc3.evt += value;
}
remove { }
}
}
public delegate void ff( int input );
public class c3
{
public event ff evt ;
public void fire()
{
Debug.WriteLine( "c3" );
evt( 10000 );
}
}
}
댓글 없음:
댓글 쓰기