-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchetsWin.cs
183 lines (165 loc) · 7.21 KB
/
SchetsWin.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;
using System.Resources;
namespace SchetsEditor
{
public class SchetsWin : Form
{
MenuStrip menuStrip;
SchetsControl schetscontrol;
ISchetsTool huidigeTool;
Panel paneel;
bool vast;
ResourceManager resourcemanager
= new ResourceManager("SchetsEditor.Properties.Resources"
, Assembly.GetExecutingAssembly()
);
private void veranderAfmeting(object o, EventArgs ea)
{
schetscontrol.Size = new Size ( this.ClientSize.Width - 70
, this.ClientSize.Height - 50);
paneel.Location = new Point(64, this.ClientSize.Height - 30);
}
private void klikToolMenu(object obj, EventArgs ea)
{
this.huidigeTool = (ISchetsTool)((ToolStripMenuItem)obj).Tag;
}
private void klikToolButton(object obj, EventArgs ea)
{
this.huidigeTool = (ISchetsTool)((RadioButton)obj).Tag;
}
private void afsluiten(object obj, EventArgs ea)
{
this.Close();
}
public SchetsWin()
{
ISchetsTool[] deTools = { new PenTool()
, new LijnTool()
, new RechthoekTool()
, new VolRechthoekTool()
, new TekstTool()
, new GumTool()
, new CirkelTool()
, new VolCirkelTool()
};
String[] deKleuren = { "Black", "Red", "Green", "Blue"
, "Yellow", "Magenta", "Cyan"
};
this.ClientSize = new Size(700, 500);
huidigeTool = deTools[0];
schetscontrol = new SchetsControl();
schetscontrol.Location = new Point(64, 10);
schetscontrol.MouseDown += (object o, MouseEventArgs mea) =>
{ vast=true;
huidigeTool.MuisVast(schetscontrol, mea.Location);
};
schetscontrol.MouseMove += (object o, MouseEventArgs mea) =>
{ if (vast)
huidigeTool.MuisDrag(schetscontrol, mea.Location);
};
schetscontrol.MouseUp += (object o, MouseEventArgs mea) =>
{ if (vast)
huidigeTool.MuisLos (schetscontrol, mea.Location);
vast = false;
};
schetscontrol.KeyPress += (object o, KeyPressEventArgs kpea) =>
{ huidigeTool.Letter (schetscontrol, kpea.KeyChar);
};
this.Controls.Add(schetscontrol);
menuStrip = new MenuStrip();
menuStrip.Visible = false;
this.Controls.Add(menuStrip);
this.maakFileMenu();
this.maakToolMenu(deTools);
this.maakAktieMenu(deKleuren);
this.maakToolButtons(deTools);
this.maakAktieButtons(deKleuren);
this.Resize += this.veranderAfmeting;
this.veranderAfmeting(null, null);
}
private void maakFileMenu()
{
ToolStripMenuItem menu = new ToolStripMenuItem("File");
menu.MergeAction = MergeAction.MatchOnly;
menu.DropDownItems.Add("Sluiten", null, this.afsluiten);
menuStrip.Items.Add(menu);
}
private void maakToolMenu(ICollection<ISchetsTool> tools)
{
ToolStripMenuItem menu = new ToolStripMenuItem("Tool");
foreach (ISchetsTool tool in tools)
{ ToolStripItem item = new ToolStripMenuItem();
item.Tag = tool;
item.Text = tool.ToString();
item.Image = (Image)resourcemanager.GetObject(tool.ToString());
item.Click += this.klikToolMenu;
menu.DropDownItems.Add(item);
}
menuStrip.Items.Add(menu);
}
private void maakAktieMenu(String[] kleuren)
{
ToolStripMenuItem menu = new ToolStripMenuItem("Aktie");
menu.DropDownItems.Add("Clear", null, schetscontrol.Schoon );
menu.DropDownItems.Add("Roteer", null, schetscontrol.Roteer );
ToolStripMenuItem submenu = new ToolStripMenuItem("Kies kleur");
foreach (string k in kleuren)
submenu.DropDownItems.Add(k, null, schetscontrol.VeranderKleurViaMenu);
menu.DropDownItems.Add(submenu);
menuStrip.Items.Add(menu);
}
private void maakToolButtons(ICollection<ISchetsTool> tools)
{
int t = 0;
foreach (ISchetsTool tool in tools)
{
RadioButton b = new RadioButton();
b.Appearance = Appearance.Button;
b.Size = new Size(45, 60);
b.Location = new Point(10, 10 + t * 55);
b.Tag = tool;
b.Text = tool.ToString();
b.Image = (Image)resourcemanager.GetObject(tool.ToString());
b.TextAlign = ContentAlignment.TopCenter;
b.ImageAlign = ContentAlignment.BottomCenter;
b.Click += this.klikToolButton;
this.Controls.Add(b);
if (t == 0) b.Select();
t++;
}
}
private void maakAktieButtons(String[] kleuren)
{
paneel = new Panel();
paneel.Size = new Size(600, 24);
this.Controls.Add(paneel);
Button b; Label l; ComboBox cbb;
b = new Button();
b.Text = "Clear";
b.Location = new Point( 0, 0);
b.Click += schetscontrol.Schoon;
paneel.Controls.Add(b);
b = new Button();
b.Text = "Rotate";
b.Location = new Point( 80, 0);
b.Click += schetscontrol.Roteer;
paneel.Controls.Add(b);
l = new Label();
l.Text = "Penkleur:";
l.Location = new Point(180, 3);
l.AutoSize = true;
paneel.Controls.Add(l);
cbb = new ComboBox(); cbb.Location = new Point(240, 0);
cbb.DropDownStyle = ComboBoxStyle.DropDownList;
cbb.SelectedValueChanged += schetscontrol.VeranderKleur;
foreach (string k in kleuren)
cbb.Items.Add(k);
cbb.SelectedIndex = 0;
paneel.Controls.Add(cbb);
}
}
}