-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIUtilities.cs
286 lines (267 loc) · 11.2 KB
/
UIUtilities.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
using System.Windows.Forms;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Instagram
{
class UIUtilities
{
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool ReleaseCapture();
public PictureBox btn_Close, btn_Minimize, btn_Maximize;
public Panel sidePanel;
private readonly bool lightModeOn;
private bool isMaximized;
private readonly int formWidth, formHeight;
private readonly Main mainForm;
private readonly Form formRef;
public UIUtilities(bool formLightModeOn)
{
lightModeOn = formLightModeOn;
}
public UIUtilities(Form f, bool formLightModeOn)
{
formWidth = f.Width;
formHeight = f.Height;
lightModeOn = formLightModeOn;
formRef = f;
if (f.WindowState == FormWindowState.Normal)
isMaximized = false;
else
isMaximized = true;
Initialize_Top_Left_Buttons();
}
public UIUtilities(Main f, bool formLightModeOn)
{
formWidth = f.Width;
formHeight = f.Height;
lightModeOn = formLightModeOn;
mainForm = f;
if (f.WindowState == FormWindowState.Normal)
isMaximized = false;
else
isMaximized = true;
Initialize_Top_Left_Buttons();
Initialize_Side_Panel();
}
private void Initialize_Top_Left_Buttons()
{
int x = formWidth, btn_Width = 45, btn_Height = 20;
string location;
Color backColor, hoverColor;
location = Return_UI_Location();
if (lightModeOn)
{
backColor = Color.FromArgb(242, 242, 242);
hoverColor = Color.FromArgb(217, 217, 217);
}
else
{
backColor = Color.FromArgb(43, 43, 43);
hoverColor = Color.FromArgb(57, 57, 57);
}
// Initializing
btn_Close = Create_Button("close", new int[] { btn_Width, btn_Height }, new int[] { x - btn_Width, 0 }, backColor, false);
btn_Maximize = Create_Button("maximize", new int[] { btn_Width, btn_Height }, new int[] { x - (btn_Width * 2), 0 }, backColor, false);
btn_Minimize = Create_Button("minimize", new int[] { btn_Width, btn_Height }, new int[] { x - (btn_Width * 3), 0 }, backColor, false);
// Setting up special settings
btn_Close.MouseClick += new MouseEventHandler((o, a) => Application.Exit());
btn_Close.MouseHover += new EventHandler((o, a) => btn_Close.BackColor = Color.Red);
btn_Close.MouseLeave += new EventHandler((o, a) => btn_Close.BackColor = backColor);
btn_Maximize.MouseClick += new MouseEventHandler((o, a) =>
{
try
{
if (!isMaximized)
{
formRef.WindowState = FormWindowState.Maximized;
isMaximized = true;
}
else
{
formRef.WindowState = FormWindowState.Normal;
isMaximized = false;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
);
btn_Maximize.MouseHover += new EventHandler((o, a) => btn_Maximize.BackColor = hoverColor);
btn_Maximize.MouseLeave += new EventHandler((o, a) => btn_Maximize.BackColor = backColor);
btn_Minimize.MouseClick += new MouseEventHandler((o, a) =>
{
formRef.WindowState = FormWindowState.Minimized;
}
);
btn_Minimize.MouseHover += new EventHandler((o, a) => btn_Minimize.BackColor = hoverColor);
btn_Minimize.MouseLeave += new EventHandler((o, a) => btn_Minimize.BackColor = backColor);
}
public void Initialize_Side_Panel()
{
int y = formHeight / 2 - 110, btn_Width = 65, btn_Height = 30;
Color panelBackgroundColor;
if (!lightModeOn)
panelBackgroundColor = Color.FromArgb(43, 43, 43);
else
panelBackgroundColor = Color.FromArgb(242, 242, 242);
// Initializing
PictureBox homeBtn, searchBtn, chatBtn, addBtn, activityBtn, accountBtn;
sidePanel = Create_Panel(new int[] { btn_Width, formHeight }, new int[] { 0, 0 }, panelBackgroundColor);
homeBtn = Create_Button("home", new int[] { btn_Width, btn_Height - 5 }, new int[] { 0, y + (int)Math.Round(btn_Height * 0.1) }, panelBackgroundColor);
chatBtn = Create_Button("chat", new int[] { btn_Width, (btn_Height - 4) }, new int[] { -1, (int)Math.Round(y + btn_Height * 1.4) }, panelBackgroundColor);
searchBtn = Create_Button("search", new int[] { btn_Width, (btn_Height - 4) }, new int[] { 0, (int)Math.Round(y + btn_Height * 2.7) }, panelBackgroundColor);
addBtn = Create_Button("plus", new int[] { btn_Width, btn_Height + 10 }, new int[] { 0, (y + (int)Math.Round((btn_Height * 3.9), MidpointRounding.AwayFromZero)) }, panelBackgroundColor);
activityBtn = Create_Button("history", new int[] { btn_Width, btn_Height + 5 }, new int[] { 0, (y + (int)Math.Round((btn_Height * 5.7), MidpointRounding.AwayFromZero)) }, panelBackgroundColor);
accountBtn = Create_Button("account", new int[] { btn_Width, btn_Height - 4 }, new int[] { 0, (y + (int)Math.Round((btn_Height * 8.5), MidpointRounding.AwayFromZero)) }, panelBackgroundColor);
homeBtn.MouseClick += new MouseEventHandler((o, a) =>
{
mainForm.Initialize_Form(0);
}
);
chatBtn.MouseClick += new MouseEventHandler((o, a) =>
{
mainForm.Initialize_Form(1);
}
);
searchBtn.MouseClick += new MouseEventHandler((o, a) =>
{
mainForm.Initialize_Form(2);
}
);
addBtn.MouseClick += new MouseEventHandler((o, a) =>
{
mainForm.Initialize_Form(3);
}
);
activityBtn.MouseClick += new MouseEventHandler((o, a) =>
{
mainForm.Initialize_Form(4);
}
);
accountBtn.MouseClick += new MouseEventHandler((o, a) =>
{
mainForm.Initialize_Form(5);
}
);
sidePanel.Controls.Add(homeBtn);
sidePanel.Controls.Add(chatBtn);
sidePanel.Controls.Add(searchBtn);
sidePanel.Controls.Add(addBtn);
sidePanel.Controls.Add(activityBtn);
sidePanel.Controls.Add(accountBtn);
}
public Panel Create_Panel(int[] size, int[] location, Color backColor)
{
Panel panel = new Panel();
panel.Width = size[0];
panel.Height = size[1];
panel.Location = new System.Drawing.Point(location[0], location[1]);
panel.BackColor = backColor;
return panel;
}
public TextBox Create_TextBox(int[] location, int[] size)
{
TextBox textBox = new TextBox();
if (!lightModeOn)
{
textBox.BackColor = Color.FromArgb(43, 43, 43);
textBox.ForeColor = Color.FromArgb(255, 255, 255);
}
else
{
textBox.BackColor = Color.FromArgb(242, 242, 242);
textBox.ForeColor = Color.FromArgb(0, 0, 0);
}
textBox.Font = new Font("Roboto", 12);
textBox.Location = new System.Drawing.Point(location[0], location[1]);
textBox.Width = size[0];
textBox.Height = size[1];
return textBox;
}
public string Return_UI_Location()
{
if (lightModeOn)
return Environment.CurrentDirectory + @"\Assets\Light Mode\UI Icons\";
else
return Environment.CurrentDirectory + @"\Assets\Dark Mode\UI Icons\";
}
public PictureBox Create_Button(string name, int[] size, int[] location, Color backColor, bool add_effects = true)
{
PictureBox btn = new PictureBox();
btn.Width = size[0];
btn.Height = size[1];
btn.ImageLocation = Return_UI_Location() + name + ".png";
btn.Location = new System.Drawing.Point(location[0], location[1]);
btn.SizeMode = PictureBoxSizeMode.Zoom;
btn.BringToFront();
if (add_effects)
{
btn.MouseHover += new EventHandler((o, a) =>
{
btn.Image.Dispose();
btn.Image = Image.FromFile(Environment.CurrentDirectory + @"\Assets\Selected Mode\" + name + ".png");
});
btn.MouseLeave += new EventHandler((o, a) =>
{
btn.Image.Dispose();
btn.Image = Image.FromFile(Return_UI_Location() + name + ".png");
});
}
btn.BackColor = backColor;
return btn;
}
public void MouseDown(IntPtr obj, object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(obj, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
public PictureBox Get_CloseBtn()
{
return btn_Close;
}
public PictureBox Get_MaximizeBtn()
{
return btn_Maximize;
}
public PictureBox Get_MinimizeBtn()
{
return btn_Minimize;
}
public Panel Get_Panel()
{
return sidePanel;
}
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
);
public void Create_Rounded_Corners()
{
mainForm.FormBorderStyle = FormBorderStyle.None;
mainForm.Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, mainForm.Width, mainForm.Height, 20, 20));
}
public void Dispose_UI_Components()
{
sidePanel.Dispose();
btn_Close.Dispose();
btn_Maximize.Dispose();
btn_Minimize.Dispose();
}
}
}