-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
221 lines (192 loc) · 6.99 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
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
using sunflower_aria2_ui.UI;
using Aria2NET;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace sunflower_aria2_ui
{
public partial class MainForm : Form
{
private Point mouseOff;//鼠标移动位置变量
private bool leftFlag;//鼠标是否为左键
bool sidebarExpand = true;//侧边栏状态
public DownloadForm downloadForm = new DownloadForm(); //子窗口准备
AboutForm aboutForm = new AboutForm();
SettingForm SettingForm = new SettingForm();
static string exePath = System.Reflection.Assembly.GetEntryAssembly().Location; // 获取当前exe的路径
static string exeDirectory = Path.GetDirectoryName(exePath); // 获取exe所在目录的路径
static string exe = Path.Combine(Path.Combine(exeDirectory, "aria2c"), "aria2c_64.exe");
Process Aria2cProcess = ExeHelper.CreateCmdProcess(exe, "--conf-path=aria2.conf", "aria2c");
private void FormSizeSetting(object sender, EventArgs e)
{
downloadForm.Width = flowLayoutPanel2.Width;
downloadForm.Height = flowLayoutPanel2.Height;
aboutForm.Width = flowLayoutPanel2.Width;
aboutForm.Height = flowLayoutPanel2.Height;
SettingForm.Width = flowLayoutPanel2.Width;
SettingForm.Height = flowLayoutPanel2.Height;
}
public MainForm()
{
InitializeComponent();
this.IsMdiContainer = true;
this.Load += new EventHandler(Form_Load);
}
private void Form_Load(object sender, EventArgs e)
{
SettingForm.Hide();
aboutForm.Hide();
downloadForm.MdiParent = this;
downloadForm.Parent = flowLayoutPanel2;
downloadForm.Show();
downloadForm.MdiParent = this;
downloadForm.Parent = flowLayoutPanel2;
button3.BackColor = Config.InvertColor();
button2.BackColor = Config.UIColor;
button5.BackColor = Config.UIColor;
Aria2cProcess.Start();
}
#region 隐藏标题栏后移动窗口
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y);//获得当前鼠标的坐标
leftFlag = true;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
this.WindowState = FormWindowState.Normal;
Point mouseSet = Control.MousePosition;//获得移动后鼠标的坐标
mouseSet.Offset(mouseOff.X, mouseOff.Y);//设置移动后的位置
Location = mouseSet;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;
}
}
#endregion
private void panel2_Click(object sender, EventArgs e)
{
flowLayoutPanel2.Visible = false;
sidebarTimer.Start();
}
private void sidebarTimer_Tick(object sender, EventArgs e)
{
if (sidebarExpand)
{
sidebar.Width -= (10 + sidebar.Width / 10);
if (sidebar.Width == sidebar.MinimumSize.Width)
{
label1.Visible = false;
button9.Image = Properties.Resources.展开菜单;
sidebarExpand = false;
flowLayoutPanel2.Visible = true;
sidebarTimer.Stop();
}
}
else
{
sidebar.Width += (10 + sidebar.Width / 10);
if (sidebar.Width == sidebar.MaximumSize.Width)
{
label1.Visible = true;
button9.Image = Properties.Resources.收起菜单;
sidebarExpand = true;
flowLayoutPanel2.Visible = true;
sidebarTimer.Stop();
}
}
}
private void button6_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button8_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void button7_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
}
else
{
this.WindowState = FormWindowState.Maximized;
}
}
private void button9_Click(object sender, EventArgs e)
{
flowLayoutPanel2.Visible = false;
//For_test();
sidebarTimer.Start();
}
private void button3_Click(object sender, EventArgs e)
{
SettingForm.Hide();
aboutForm.Hide();
downloadForm.MdiParent = this;
downloadForm.Parent = flowLayoutPanel2;
downloadForm.Show();
downloadForm.MdiParent = this;
downloadForm.Parent = flowLayoutPanel2;
button3.BackColor = Config.InvertColor();
button2.BackColor = Config.UIColor;
button5.BackColor = Config.UIColor;
}
private void button2_Click(object sender, EventArgs e)
{
aboutForm.Hide();
downloadForm.Hide();
SettingForm.MdiParent = this;
SettingForm.Parent = flowLayoutPanel2;
SettingForm.Show();
SettingForm.MdiParent = this;
SettingForm.Parent = flowLayoutPanel2;
button2.BackColor = Config.InvertColor();
button3.BackColor = Config.UIColor;
button5.BackColor = Config.UIColor;
}
private void button5_Click(object sender, EventArgs e)
{
SettingForm.Hide();
downloadForm.Hide();
aboutForm.MdiParent = this;
aboutForm.Parent = flowLayoutPanel2;
aboutForm.Show();
aboutForm.MdiParent = this;
aboutForm.Parent = flowLayoutPanel2;
button5.BackColor = Config.InvertColor();
button2.BackColor = Config.UIColor;
button3.BackColor = Config.UIColor;
}
private void tableLayoutPanel1_DoubleClick(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
}
else
{
this.WindowState = FormWindowState.Maximized;
}
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
Aria2cProcess.Kill();
}
}
}