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

Commit

Permalink
Added dark theme support
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaczero committed Dec 8, 2019
1 parent 57481f8 commit a71c199
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 70 deletions.
25 changes: 25 additions & 0 deletions DNSChanger/DNSChangeDetectedForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

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

if (Utilities.IsSystemDarkMode())
{
BackColor = Color.FromArgb(0x20, 0x20, 0x20);
ForeColor = Color.FromArgb(0xF0, 0xF0, 0xF0);

foreach (Control control in Controls)
{
if (control is Button)
{
var btn = control as Button;
btn.FlatStyle = FlatStyle.Flat;
btn.UseVisualStyleBackColor = false;
}

if (control is TextBox)
{
var tb = control as TextBox;
tb.BackColor = Color.FromArgb(0x30, 0x30, 0x30);
tb.ForeColor = Color.FromArgb(0xF0, 0xF0, 0xF0);
tb.BorderStyle = BorderStyle.FixedSingle;
}
}
}


var @interface = DNSValidate.GetInterfaceToValidate().Value;
interfaceTb.Text = @interface.Name;
Expand Down
127 changes: 65 additions & 62 deletions DNSChanger/InterfaceSelectionForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions DNSChanger/InterfaceSelectionForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DNSChanger.Structs;
using System;
using System.Drawing;
using System.Windows.Forms;

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

if (Utilities.IsSystemDarkMode())
{
BackColor = Color.FromArgb(0x20, 0x20, 0x20);
ForeColor = Color.FromArgb(0xF0, 0xF0, 0xF0);

foreach (Control control in Controls)
{
if (control is Button)
{
var btn = control as Button;
btn.FlatStyle = FlatStyle.Flat;
btn.UseVisualStyleBackColor = false;
}
}
}


FillInterfaces();
}
Expand Down
5 changes: 1 addition & 4 deletions DNSChanger/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 36 additions & 2 deletions DNSChanger/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ public MainForm()
Text = GlobalVars.Name;
Icon = Properties.Resources.Icon;

if (Utilities.IsSystemDarkMode())
{
BackColor = Color.FromArgb(0x20, 0x20, 0x20);
ForeColor = Color.FromArgb(0xF0, 0xF0, 0xF0);

foreach (Control control in Controls)
{
if (control is Button)
{
var btn = control as Button;
btn.FlatStyle = FlatStyle.Flat;
btn.UseVisualStyleBackColor = false;
}

if (control is TextBox)
{
var tb = control as TextBox;
tb.BackColor = Color.FromArgb(0x30, 0x30, 0x30);
tb.ForeColor = Color.FromArgb(0xF0, 0xF0, 0xF0);
tb.BorderStyle = BorderStyle.FixedSingle;
}
}
}


_interfaceToValidate = DNSValidate.GetInterfaceToValidate();
if (_interfaceToValidate.HasValue)
Expand Down Expand Up @@ -308,16 +332,26 @@ private void resetBtn_Click(object sender, EventArgs e)
private void ButtonSuccessAnimation(object sender)
{
var btn = sender as Button;
btn.BackColor = Color.LightGreen;
var defaultColor = btn.BackColor;

if (Utilities.IsSystemDarkMode())
{
btn.BackColor = Color.FromArgb(0x10, 0x50, 0x10);
}
else
{
btn.BackColor = Color.LightGreen;
}

var thr = new Thread(() =>
{
Thread.Sleep(600);
btn.BackColor = SystemColors.Control;
btn.BackColor = defaultColor;
}) {IsBackground = true};
thr.Start();
}


private void validateCb_CheckedChanged(object sender, EventArgs e)
{
if (validateCb.Checked)
Expand Down
2 changes: 1 addition & 1 deletion DNSChanger/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Security.Principal;
using System.Windows.Forms;

namespace DNSChanger
Expand Down Expand Up @@ -30,6 +29,7 @@ public static void Main(string[] args)
}
catch (Exception ex)
{ }

return;
}

Expand Down
12 changes: 12 additions & 0 deletions DNSChanger/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Management;
using System.Security.Principal;
using Microsoft.Win32;

namespace DNSChanger
{
Expand All @@ -28,7 +29,18 @@ public static string GetCommandLine(this Process process)
{
return objects.Cast<ManagementBaseObject>().SingleOrDefault()?["CommandLine"]?.ToString();
}
}

private static bool? _isSystemDarkMode;
public static bool IsSystemDarkMode()
{
if (_isSystemDarkMode.HasValue) return _isSystemDarkMode.Value;

var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", false);
if (key == null) return false;

var val = (int) key.GetValue("AppsUseLightTheme", 1);
return (_isSystemDarkMode = val == 0).Value;
}
}
}
2 changes: 1 addition & 1 deletion DNSChanger/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
Expand Down

0 comments on commit a71c199

Please sign in to comment.