-
Notifications
You must be signed in to change notification settings - Fork 1
/
FormMain.cs
307 lines (270 loc) · 10.4 KB
/
FormMain.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
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.IO;
using System.Runtime.InteropServices;
using System.Net;
namespace LectureSelector
{
public partial class FormMain : System.Windows.Forms.Form
{
/*
public void GenerateFile(string path)
{
var res = File.ReadAllText(path).Split(new string[] { "\n\r\n\r" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < res.Length; i++)
{
var w = File.CreateText(@".\gen\" + (i + 1).ToString() + ".txt");
w.WriteLine(res[i]);
w.Close();
}
}
*/
private bool initConfigure()
{
if (!Directory.Exists(@".\new"))
try
{
Directory.CreateDirectory(@".\new");
}
catch (IOException)
{
MessageBox.Show("无法创建new文件夹","错误");
return false;
}
if (!Directory.Exists(@".\old"))
try
{
Directory.CreateDirectory(@".\old");
}
catch (IOException)
{
MessageBox.Show("无法创建old文件夹", "错误");
return false;
}
return true;
}
private int high = 0, low = 0;
private bool moved = false;
private bool state = false;
private int number = 88;
private int time = 0;
public FormMain()
{
//GenerateFile(".\\file.txt");
InitializeComponent();
#if DEBUG
textBoxPassword.Visible = false;
buttonRun.Visible = true;
#endif
}
private void FormMain_SizeChanged(object sender, EventArgs e)
{
if (!moved)
{
labelHigh.Left = Width / 2 - labelHigh.Width;
labelLow.Left = Width / 2;
labelHigh.Top = Height / 2 - labelHigh.Height;
labelLow.Top = Height / 2 - labelLow.Height;
}
buttonClose.Left = Width - buttonClose.Width;
buttonClose.Top = 0;
buttonMaxiumum.Left = Width - buttonClose.Width - buttonMaxiumum.Width;
buttonMaxiumum.Top = 0;
buttonRun.Left = Width / 2 - buttonRun.Width / 2;
buttonRun.Top = Height - buttonRun.Height - Height / 20;
textBoxPassword.Left = Width / 2 - textBoxPassword.Width / 2;
textBoxPassword.Top = Height - textBoxPassword.Height - Height / 20;
richTextBoxMain.Height = 17 * (Height - buttonClose.Height) / 20;
richTextBoxMain.Width = 17 * Width / 20;
richTextBoxMain.Left = Width / 2 - richTextBoxMain.Width / 2;
richTextBoxMain.Top = Height / 2 - richTextBoxMain.Height / 2;
numericUpDownFontSize.Left = Width / 2 - numericUpDownFontSize.Width / 2;
numericUpDownFontSize.Top = Height - numericUpDownFontSize.Height - Height / 40;
checkBoxDebug.Left = 3;
checkBoxDebug.Top = Height - checkBoxDebug.Height - 3;
labelTime.Top = 8;
labelTime.Left = Width / 2 - labelTime.Width / 2;
}
private void buttonClose_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
private void buttonMaxiumum_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
}
private void timerMain_Tick(object sender, EventArgs e)
{
var rnd = new Random();
high = rnd.Next(0, 9);
low = rnd.Next(0, 9);
labelHigh.Text = high.ToString();
labelLow.Text = low.ToString();
}
private void buttonRun_Click(object sender, EventArgs e)
{
if (state)
{
var paths = Directory.GetFiles(@".\new");
if (paths.Length > 0)
{
var index = (new Random()).Next(0, paths.Length - 1);
var path = paths[index];
number = int.Parse(Path.GetFileNameWithoutExtension(path));
if (File.Exists(path))
{
var str = File.ReadAllText(path);
richTextBoxMain.Text = str
.Replace("\n", "\n ")
.Replace(" *", " ※ ");
#if !DEBUG
if (!checkBoxDebug.Checked)
File.Move(path, @".\old\" + Path.GetFileName(path));
#endif
}
}
labelHigh.Text = ((number - number % 10) / 10).ToString();
labelLow.Text = (number % 10).ToString();
timerMain.Stop();
state = false;
buttonRun.Visible = false;
timerFade.Start();
}
else
{
timerMain.Start();
state = true;
buttonRun.Text = "结束";
}
}
private void timerFade_Tick(object sender, EventArgs e)
{
labelHigh.Visible = false;
labelLow.Visible = false;
labelHigh.Font = new Font("微软雅黑", 18);
labelLow.Font = new Font("微软雅黑", 18);
labelHigh.Left = 5;
labelLow.Left = labelHigh.Width + 5;
labelHigh.Top = 3;
labelLow.Top = 3;
labelHigh.Visible = true;
labelLow.Visible = true;
moved = true;
richTextBoxMain.Visible = true;
numericUpDownFontSize.Visible = true;
labelTime.Visible = true;
timerCount.Start();
timerFade.Stop();
}
private void FormMain_Load(object sender, EventArgs e)
{
initConfigure();
richTextBoxMain.SelectionIndent = 4;
richTextBoxMain.SelectionRightIndent = 4;
}
const int CURSOR_HTLEFT = 10;
const int CURSOR_HTRIGHT = 11;
const int CURSOR_HTTOP = 12;
const int CURSOR_HTTOPLEFT = 13;
const int CURSOR_HTTOPRIGHT = 14;
const int CURSOR_HTBOTTOM = 15;
const int CURSOR_HTBOTTOMLEFT = 16;
const int CURSOR_HTBOTTOMRIGHT = 17;
private void numericUpDownFontSize_ValueChanged(object sender, EventArgs e)
{
richTextBoxMain.Font = new Font("微软雅黑", (float)(numericUpDownFontSize.Value > 8 ? numericUpDownFontSize.Value : 8));
}
private void timerCount_Tick(object sender, EventArgs e)
{
time++;
labelTime.Text = $"{((time - time % 60) / 60):00}:{(time % 60):00}";
}
private void textBoxPassword_TextChanged(object sender, EventArgs e)
{
if (textBoxPassword.Text == "0987")
{
textBoxPassword.Visible = false;
buttonRun.Visible = true;
}
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x0084:
base.WndProc(ref m);
Point vPoint = new Point((int)m.LParam & 0xFFFF,
(int)m.LParam >> 16 & 0xFFFF);
vPoint = PointToClient(vPoint);
if (vPoint.X <= 5)
if (vPoint.Y <= 5)
m.Result = (IntPtr)CURSOR_HTTOPLEFT;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)CURSOR_HTBOTTOMLEFT;
else m.Result = (IntPtr)CURSOR_HTLEFT;
else if (vPoint.X >= ClientSize.Width - 5)
if (vPoint.Y <= 5)
m.Result = (IntPtr)CURSOR_HTTOPRIGHT;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)CURSOR_HTBOTTOMRIGHT;
else m.Result = (IntPtr)CURSOR_HTRIGHT;
else if (vPoint.Y <= 5)
m.Result = (IntPtr)CURSOR_HTTOP;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)CURSOR_HTBOTTOM;
break;
case 0x0201: //鼠标左键按下的消息
m.Msg = 0x00A1; //更改消息为非客户区按下鼠标
m.LParam = IntPtr.Zero; //默认值
m.WParam = new IntPtr(2);//鼠标放在标题栏内
base.WndProc(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
/*
public bool httpDownload(string url, string path)
{
string tempPath = Path.GetDirectoryName(path) + @"\temp";
Directory.CreateDirectory(tempPath);
string tempFile = tempPath + @"\" + Path.GetFileName(path) + ".temp";
if (File.Exists(tempFile))
{
File.Delete(tempFile);
}
try
{
FileStream fs = new FileStream(tempFile, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream responseStream = response.GetResponseStream();
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, (int)bArr.Length);
while (size > 0)
{
fs.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, (int)bArr.Length);
}
fs.Close();
responseStream.Close();
File.Move(tempFile, path);
return true;
}
catch (Exception ex)
{
MessageBox.Show("远程连接失败", "错误");
return false;
}
}
*/
}
}