2003-10-05 Todd Berman <tberman@gentoo.org>
[mono.git] / mcs / tests / test-57.cs
1 using System;
2
3 public delegate void EventHandler (int i, int j);
4
5 public class Button {
6
7         private EventHandler click;
8
9         public event EventHandler Click {
10                 add    { click += value; }
11                 remove { click -= value; }
12         }
13
14         public void OnClick (int i, int j)
15         {
16                 if (click == null) {
17                         Console.WriteLine ("Nothing to click!");
18                         return;
19                 }
20
21                 click (i, j);
22         }
23
24         public void Reset ()
25         {
26                 click = null;
27         }
28 }
29
30 public class Blah {
31
32         Button Button1 = new Button ();
33
34         public void Connect ()
35         {
36                 Button1.Click += new EventHandler (Button1_Click);
37                 Button1.Click += new EventHandler (Foo_Click);
38         }
39
40         public void Button1_Click (int i, int j)
41         {
42                 Console.WriteLine ("Button1 was clicked !");
43                 Console.WriteLine ("Answer : " + (i+j));
44         }
45
46         public void Foo_Click (int i, int j)
47         {
48                 Console.WriteLine ("Foo was clicked !");
49                 Console.WriteLine ("Answer : " + (i+j));
50         }
51
52         public void Disconnect ()
53         {
54                 Console.WriteLine ("Disconnecting Button1's handler ...");
55                 Button1.Click -= new EventHandler (Button1_Click);
56         }
57
58         public static int Main ()
59         {
60                 Blah b = new Blah ();
61
62                 b.Connect ();
63
64                 b.Button1.OnClick (2, 3);
65
66                 b.Disconnect ();
67
68                 Console.WriteLine ("Now calling OnClick again");
69                 b.Button1.OnClick (3, 7);
70
71                 Console.WriteLine ("Events test passes");
72                 return 0;
73         }
74         
75 }