This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainPage.cs
203 lines (190 loc) · 6.53 KB
/
MainPage.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
using Microsoft.Win32;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Windows_Cleanup.Helper;
using Windows_Cleanup.Views;
namespace Windows_Cleanup
{
public partial class MainPage : Form, IDisposable
{
public Button buttonHome, buttonSettings, buttonBasicTools, buttonNetTools;
public static MainPage? mainPageInstance { get; set; }
readonly HomeView homeView = new();
readonly SettingsView settingsView = new();
readonly BasicToolsView basicToolsView = new();
readonly NetToolsView netToolsView = new();
readonly ThemeHelper themeHelper = new();
[LibraryImport("DwmApi")]
private static partial int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize);
public MainPage()
{
InitializeComponent();
AutoScaleMode = AutoScaleMode.Dpi;
OptimizedDoubleBuffer();
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
mainPageInstance = this;
buttonHome = btnHome;
buttonSettings = btnSettings;
buttonBasicTools = btnBasicTools;
buttonNetTools = btnNetTools;
Disposed += new EventHandler(Form_Disposed);
}
private void Form_Disposed(object? sender, EventArgs e)
{
SystemEvents.UserPreferenceChanged -= SystemEvents_UserPreferenceChanged;
}
private void MainPage_Load(object sender, EventArgs e)
{
panel3.Tag = "HomeView";
switchPanel(homeView);
ThemeHelper.buttonBorderClear();
btnHome.FlatAppearance.BorderSize = 1;
}
public void memoryFreeUp()
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
return;
}
public void cmdExec(string? proc, string? args)
{
Process process = new();
try
{
process.StartInfo.FileName = proc;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = false;
process.StartInfo.UseShellExecute = false;
process.Start();
process.StandardInput.WriteLine(args);
process.WaitForExit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "" + ex);
}
finally
{
process.StandardInput.Flush();
process.StandardInput.Close();
}
}
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
if (e.Category == UserPreferenceCategory.VisualStyle || e.Category == UserPreferenceCategory.General)
{
// Windows theme has changed, so update the application theme
themeChecker();
}
}
public void themeChecker()
{
var lightmode = (int)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", "1")!;
if (!ThemeHelper.AppsUseLightTheme())
{
ThemeHelper.DarkTheme();
}
else
{
ThemeHelper.LightTheme();
}
if (lightmode != 1) // Dark Mode
{
if (DwmSetWindowAttribute(Handle, 19, new[] { 1 }, 4) != 0)
{
DwmSetWindowAttribute(Handle, 20, new[] { 1 }, 4);
}
}
else if (lightmode == 1)// Light Mode
{
DwmSetWindowAttribute(Handle, 19, new[] { 0 }, 4);
}
}
public void switchPanel(Form panel)
{
panel3.Controls.Clear();
panel.TopLevel = false;
panel.FormBorderStyle = FormBorderStyle.None;
panel.Dock = DockStyle.Fill;
//panel.AutoSize = true;
//panel.AutoSizeMode = AutoSizeMode.GrowOnly;
//panel.AutoScroll = true;
panel3.Controls.Add(panel);
panel3.AutoSize = true;
panel.TopMost = true;
panel.BringToFront();
panel.Show();
panel.AutoScaleMode = AutoScaleMode.Dpi;
return;
}
public void OptimizedDoubleBuffer()
{
this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
return;
}
private void btnHome_Click(object sender, EventArgs e)
{
if (panel3.Tag?.ToString() == "HomeView")
{
return;
}
else
{
panel3.Tag = "HomeView";
ThemeHelper.buttonBorderClear();
btnHome.FlatAppearance.BorderSize = 1;
switchPanel(homeView);
return;
}
}
private void btnSettings_Click(object sender, EventArgs e)
{
if (panel3.Tag?.ToString() == "SettingsView")
{
return;
}
else
{
panel3.Tag = "SettingsView";
ThemeHelper.buttonBorderClear();
btnSettings.FlatAppearance.BorderSize = 1;
switchPanel(settingsView);
return;
}
}
private void btnBasicTools_Click(object sender, EventArgs e)
{
if (panel3.Tag?.ToString() == "BasicToolsView")
{
return;
}
else
{
panel3.Tag = "BasicToolsView";
ThemeHelper.buttonBorderClear();
btnBasicTools.FlatAppearance.BorderSize = 1;
switchPanel(basicToolsView);
return;
}
}
private void btnNetTools_Click(object sender, EventArgs e)
{
if (panel3.Tag?.ToString() == "NetToolsView")
{
return;
}
else
{
panel3.Tag = "NetToolsView";
ThemeHelper.buttonBorderClear();
btnNetTools.FlatAppearance.BorderSize = 1;
switchPanel(netToolsView);
return;
}
}
}
}