-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainForm.cs
155 lines (144 loc) · 5.12 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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
namespace BotisButtonBoard
{
public partial class mainForm : Form
{
private List<buttonControl> buttonList = new List<buttonControl>();
public mainForm()
{
InitializeComponent();
this.FormClosing += Form1_Closing;
this.Load += Form1_Load;
}
private void button1_Click(object sender, EventArgs e)
{
buttonControl btn = addButtonControl();
btn.addOutput();
}
private buttonControl addButtonControl(string name = "New Button")
{
buttonControl buttonGroup1 = new buttonControl();
buttonGroup1.btnName = name;
this.tableLayoutPanel1.Controls.Add(buttonGroup1);
buttonList.Add(buttonGroup1);
return buttonGroup1;
}
private void Form1_Load(object sender, System.EventArgs e)
{
if (System.IO.File.Exists(Application.StartupPath + @"\settings.xml")) {
//FormSerialisor.Deserialise(this, Application.StartupPath + @"\settings.xml");
XDocument doc = XDocument.Load(Application.StartupPath + @"\settings.xml");
foreach (var elem in doc.Descendants("Root").Elements())
{
if (elem.Name=="Group")
{
buttonControl btn = addButtonControl(elem.Element("btnName").Value);
foreach (var output in elem.Element("outputs").Elements())
{
btn.addOutput(output.Element("fileLocation").Value,output.Element("fileContents").Value);
}
} else if (elem.Name== "alwaysOnTop")
{
if (elem.Value=="true")
{
this.TopMost = true;
checkBox1.Checked = true;
} else
{
this.TopMost = false;
checkBox1.Checked = false;
}
} else if (elem.Name=="size")
{
this.Size = new Size(Int32.Parse(elem.Element("width").Value),Int32.Parse(elem.Element("height").Value));
}
}
}
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//FormSerialisor.Serialise(this, Application.StartupPath + @"\settings.xml");
XElement srcTree = new XElement(new XElement("Root"));
foreach (buttonControl btnGroup in buttonList)
{
XElement outputs = new XElement("outputs");
foreach (outputControl output in btnGroup.outputList)
{
outputs.Add(new XElement("output",
new XElement("fileLocation", output.fileLocation),
new XElement("fileContents", output.fileContents)
));
}
srcTree.Add(
new XElement("Group",
new XElement("btnName", btnGroup.btnName),
outputs
)
);
}
srcTree.Add(new XElement("alwaysOnTop", this.TopMost));
srcTree.Add(new XElement("size",
new XElement("width", this.Size.Width),
new XElement("height", this.Size.Height)
));
srcTree.Save(Application.StartupPath + @"\settings.xml");
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
this.TopMost = true;
} else
{
this.TopMost = false;
}
}
private void checkBoxShowDetails_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxShowDetails.Checked)
{
foreach(Control c in this.tableLayoutPanel1.Controls)
{
showDetails(c);
}
} else
{
foreach(Control c in this.tableLayoutPanel1.Controls)
{
hideDetails(c);
}
}
}
private void showDetails(Control c)
{
if (c.Name != "button1")
{
c.Show();
}
foreach (Control t in c.Controls)
showDetails(t);
}
private void hideDetails(Control c)
{
if (c.Name != "button1")
{
c.Hide();
} else
{
c.Parent.Show();
c.Parent.Parent.Show();
}
foreach (Control t in c.Controls)
hideDetails(t);
}
}
}