Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-57.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9f4c1b82f86920ec9448a703b8ea60e003ce59ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;

public delegate void EventHandler (int i, int j);

public class Button {

	private EventHandler click;

	public event EventHandler Click {
		add    { click += value; }
		remove { click -= value; }
	}

        public void OnClick (int i, int j)
  	{
  		if (click == null) {
			Console.WriteLine ("Nothing to click!");
			return;
		}

		click (i, j);
 	}

	public void Reset ()
	{
		click = null;
	}
}

public class Blah {

	Button Button1 = new Button ();

	public void Connect ()
	{
		Button1.Click += new EventHandler (Button1_Click);
		Button1.Click += new EventHandler (Foo_Click);
		Button1.Click += null;
	}

	public void Button1_Click (int i, int j)
	{
		Console.WriteLine ("Button1 was clicked !");
		Console.WriteLine ("Answer : " + (i+j));
	}

	public void Foo_Click (int i, int j)
	{
		Console.WriteLine ("Foo was clicked !");
		Console.WriteLine ("Answer : " + (i+j));
	}

	public void Disconnect ()
	{
		Console.WriteLine ("Disconnecting Button1's handler ...");
		Button1.Click -= new EventHandler (Button1_Click);
	}

	public static int Main ()
	{
		Blah b = new Blah ();

		b.Connect ();

		b.Button1.OnClick (2, 3);

		b.Disconnect ();

		Console.WriteLine ("Now calling OnClick again");
		b.Button1.OnClick (3, 7);

		Console.WriteLine ("Events test passes");
		return 0;
	}
	
}