In fact, at the beginning, I was a little confused about the incident and delegation. I went to find some information and expected to see a good article, which benefited a lot.
The following is an imitation click event I wrote after reading it.
1 public class button
2 {
3 Public string name = "I Am a button ";
4 Public Delegate void clickeventhandler (Object sender, clickeventargs E );
5 public event clickeventhandler click;
6 public class clickeventargs: eventargs
7 {
8 Public readonly string name;
9 Public clickeventargs (string name)
10 {
11 This. Name = Name;
12}
13}
14 public virtual void onclick (clickeventargs E)
15 {
16 if (Click! = NULL)
17 {
18 click (this, e );
19}
20}
21 public void danji ()
22 {
23 clickeventargs E = new clickeventargs (name );
24 onclick (E );
25}
26
27}
28 public class task
29 {
30 public void onclick (Object sender, button. clickeventargs E)
31 {
32 console. writeline (E. Name );
33}
34}
35 class clickevent
36 {
37 static void main (string [] ARGs)
38 {
39 button BTN = new button ();
40 BTN. Click + = (new task (). onclick;
41 BTN. danji ();
42}
43}
That article is very well written. I will not introduce it. I will give you a URL. You can check it out.
Http://www.cnblogs.com/JimmyZhang/archive/2007/09/23/903360.html