Skip to content
This repository was archived by the owner on Jun 23, 2022. It is now read-only.

Commit a71c199

Browse files
committed
Added dark theme support
1 parent 57481f8 commit a71c199

File tree

8 files changed

+158
-70
lines changed

8 files changed

+158
-70
lines changed

DNSChanger/DNSChangeDetectedForm.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5+
using System.Drawing;
56
using System.Linq;
67
using System.Windows.Forms;
78

@@ -15,6 +16,30 @@ public DNSChangeDetectedForm()
1516
Text = GlobalVars.Name + @" DNS Change Detected";
1617
Icon = Properties.Resources.Icon;
1718

19+
if (Utilities.IsSystemDarkMode())
20+
{
21+
BackColor = Color.FromArgb(0x20, 0x20, 0x20);
22+
ForeColor = Color.FromArgb(0xF0, 0xF0, 0xF0);
23+
24+
foreach (Control control in Controls)
25+
{
26+
if (control is Button)
27+
{
28+
var btn = control as Button;
29+
btn.FlatStyle = FlatStyle.Flat;
30+
btn.UseVisualStyleBackColor = false;
31+
}
32+
33+
if (control is TextBox)
34+
{
35+
var tb = control as TextBox;
36+
tb.BackColor = Color.FromArgb(0x30, 0x30, 0x30);
37+
tb.ForeColor = Color.FromArgb(0xF0, 0xF0, 0xF0);
38+
tb.BorderStyle = BorderStyle.FixedSingle;
39+
}
40+
}
41+
}
42+
1843

1944
var @interface = DNSValidate.GetInterfaceToValidate().Value;
2045
interfaceTb.Text = @interface.Name;

DNSChanger/InterfaceSelectionForm.Designer.cs

Lines changed: 65 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DNSChanger/InterfaceSelectionForm.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using DNSChanger.Structs;
22
using System;
3+
using System.Drawing;
34
using System.Windows.Forms;
45

56
namespace DNSChanger
@@ -15,6 +16,22 @@ public InterfaceSelectionForm()
1516
Text = GlobalVars.Name + @" Interface Selector";
1617
Icon = Properties.Resources.Icon;
1718

19+
if (Utilities.IsSystemDarkMode())
20+
{
21+
BackColor = Color.FromArgb(0x20, 0x20, 0x20);
22+
ForeColor = Color.FromArgb(0xF0, 0xF0, 0xF0);
23+
24+
foreach (Control control in Controls)
25+
{
26+
if (control is Button)
27+
{
28+
var btn = control as Button;
29+
btn.FlatStyle = FlatStyle.Flat;
30+
btn.UseVisualStyleBackColor = false;
31+
}
32+
}
33+
}
34+
1835

1936
FillInterfaces();
2037
}

DNSChanger/MainForm.Designer.cs

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DNSChanger/MainForm.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@ public MainForm()
2121
Text = GlobalVars.Name;
2222
Icon = Properties.Resources.Icon;
2323

24+
if (Utilities.IsSystemDarkMode())
25+
{
26+
BackColor = Color.FromArgb(0x20, 0x20, 0x20);
27+
ForeColor = Color.FromArgb(0xF0, 0xF0, 0xF0);
28+
29+
foreach (Control control in Controls)
30+
{
31+
if (control is Button)
32+
{
33+
var btn = control as Button;
34+
btn.FlatStyle = FlatStyle.Flat;
35+
btn.UseVisualStyleBackColor = false;
36+
}
37+
38+
if (control is TextBox)
39+
{
40+
var tb = control as TextBox;
41+
tb.BackColor = Color.FromArgb(0x30, 0x30, 0x30);
42+
tb.ForeColor = Color.FromArgb(0xF0, 0xF0, 0xF0);
43+
tb.BorderStyle = BorderStyle.FixedSingle;
44+
}
45+
}
46+
}
47+
2448

2549
_interfaceToValidate = DNSValidate.GetInterfaceToValidate();
2650
if (_interfaceToValidate.HasValue)
@@ -308,16 +332,26 @@ private void resetBtn_Click(object sender, EventArgs e)
308332
private void ButtonSuccessAnimation(object sender)
309333
{
310334
var btn = sender as Button;
311-
btn.BackColor = Color.LightGreen;
335+
var defaultColor = btn.BackColor;
336+
337+
if (Utilities.IsSystemDarkMode())
338+
{
339+
btn.BackColor = Color.FromArgb(0x10, 0x50, 0x10);
340+
}
341+
else
342+
{
343+
btn.BackColor = Color.LightGreen;
344+
}
312345

313346
var thr = new Thread(() =>
314347
{
315348
Thread.Sleep(600);
316-
btn.BackColor = SystemColors.Control;
349+
btn.BackColor = defaultColor;
317350
}) {IsBackground = true};
318351
thr.Start();
319352
}
320353

354+
321355
private void validateCb_CheckedChanged(object sender, EventArgs e)
322356
{
323357
if (validateCb.Checked)

DNSChanger/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Diagnostics;
33
using System.Linq;
4-
using System.Security.Principal;
54
using System.Windows.Forms;
65

76
namespace DNSChanger
@@ -30,6 +29,7 @@ public static void Main(string[] args)
3029
}
3130
catch (Exception ex)
3231
{ }
32+
3333
return;
3434
}
3535

DNSChanger/Utilities.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Management;
44
using System.Security.Principal;
5+
using Microsoft.Win32;
56

67
namespace DNSChanger
78
{
@@ -28,7 +29,18 @@ public static string GetCommandLine(this Process process)
2829
{
2930
return objects.Cast<ManagementBaseObject>().SingleOrDefault()?["CommandLine"]?.ToString();
3031
}
32+
}
33+
34+
private static bool? _isSystemDarkMode;
35+
public static bool IsSystemDarkMode()
36+
{
37+
if (_isSystemDarkMode.HasValue) return _isSystemDarkMode.Value;
38+
39+
var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", false);
40+
if (key == null) return false;
3141

42+
var val = (int) key.GetValue("AppsUseLightTheme", 1);
43+
return (_isSystemDarkMode = val == 0).Value;
3244
}
3345
}
3446
}

DNSChanger/app.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Remove this element if your application requires this virtualization for backwards
1717
compatibility.
1818
-->
19-
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
19+
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
2020
</requestedPrivileges>
2121
</security>
2222
</trustInfo>

0 commit comments

Comments
 (0)