-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainForm.cs
62 lines (53 loc) · 1.62 KB
/
MainForm.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ObserverPattern.ObserverPattern.Subject;
using ObserverPattern.ObserverPattern.Observer;
namespace ObserverPattern
{
public partial class MainForm : Form
{
private ColorSubject _subject = new ColorSubject();
public MainForm()
{
InitializeComponent();
// Initialize
nextLeft = 0;
ColorCombo.SelectedColor = _subject.Color;
Application.DoEvents();
Add3ObserverForms();
}
private int nextTop = 0;
private int nextLeft = 0;
private void Add3ObserverForms()
{
for (int i = 1; i <= 5; i++)
{
SetCommonProperties(new BallObserver());
SetCommonProperties(new SimpleObserver());
SetCommonProperties(new MovingBallObserver());
nextLeft += 300;
nextTop = 0;
}
}
private void SetCommonProperties(Form form)
{
form.Left = nextLeft;
form.Top = nextTop;
form.StartPosition = FormStartPosition.Manual;
(form as IObserver).ColorChanged(_subject.Color);
form.Show();
_subject.Register(form as IObserver);
nextTop += form.Height;
}
private void ColorCombo_SelectedIndexChanged(object sender, EventArgs e)
{
_subject.Color = ColorCombo.SelectedColor;
}
}
}