Skip to content

Commit 8989f41

Browse files
Added a dark mode
1 parent d395e60 commit 8989f41

File tree

11 files changed

+677
-186
lines changed

11 files changed

+677
-186
lines changed

.vs/imageResizer/v17/.suo

-5.5 KB
Binary file not shown.

imageResizer/AboutBox.Designer.cs

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

imageResizer/AboutBox.cs

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,130 @@
1-
using System;
1+
using Microsoft.Win32;
2+
using System;
3+
using System.Drawing;
4+
using System.Globalization;
5+
using System.Runtime.InteropServices;
26
using System.Windows.Forms;
37

48
namespace imageResizer
59
{
610
public partial class AboutBox : Form
711
{
12+
internal Options Options { get; set; }
13+
814
public AboutBox()
915
{
1016
InitializeComponent();
1117
}
1218

13-
private void buttonOK_Click(object sender, EventArgs e)
19+
private void ButtonOK_Click(object sender, EventArgs e)
1420
{
1521
this.Close();
1622
}
1723

18-
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
24+
private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
1925
{
2026
System.Diagnostics.Process.Start("https://github.com/borisonekenobi/");
2127
}
2228

23-
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
29+
private void LinkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
2430
{
2531
System.Diagnostics.Process.Start("mailto:borisonekenobi@gmail.com");
2632
}
2733

2834
private void AboutBox_Load(object sender, EventArgs e)
2935
{
36+
UpdateTheme();
3037
label5.Text = "Current: v" + Form1.CurrentVersion + "\nLatest: v" + Form1.LatestVersion;
3138
}
39+
40+
private void UpdateTheme()
41+
{
42+
if (Options.Theme == 0)
43+
{
44+
SetLightTheme();
45+
}
46+
else if (Options.Theme == 1)
47+
{
48+
SetDarkTheme();
49+
}
50+
else
51+
{
52+
if (UsingLightTheme())
53+
{
54+
SetLightTheme();
55+
}
56+
else
57+
{
58+
SetDarkTheme();
59+
}
60+
}
61+
}
62+
63+
private void SetLightTheme()
64+
{
65+
BackColor = DefaultBackColor;
66+
ForeColor = DefaultForeColor;
67+
68+
buttonOK.BackColor = DefaultBackColor;
69+
buttonOK.FlatAppearance.BorderSize = 1;
70+
}
71+
72+
private void SetDarkTheme()
73+
{
74+
BackColor = backgroundColor;
75+
ForeColor = foregroundColor;
76+
77+
buttonOK.BackColor = buttonColor;
78+
buttonOK.FlatAppearance.BorderSize = buttonBorderSize;
79+
}
80+
81+
private static bool UsingLightTheme()
82+
{
83+
var registryKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
84+
var appsUseLightTheme = registryKey?.GetValue("AppsUseLightTheme");
85+
86+
if (appsUseLightTheme is null)
87+
{
88+
return true;
89+
}
90+
else
91+
{
92+
return Convert.ToBoolean(appsUseLightTheme, CultureInfo.InvariantCulture);
93+
}
94+
}
95+
96+
[DllImport("dwmapi.dll")]
97+
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
98+
99+
private const int DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19;
100+
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
101+
102+
internal static bool UseImmersiveDarkMode(IntPtr handle, bool enabled)
103+
{
104+
if (IsWindows10OrGreater(17763))
105+
{
106+
var attribute = DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1;
107+
if (IsWindows10OrGreater(18985))
108+
{
109+
attribute = DWMWA_USE_IMMERSIVE_DARK_MODE;
110+
}
111+
112+
int useImmersiveDarkMode = enabled ? 1 : 0;
113+
return DwmSetWindowAttribute(handle, (int)attribute, ref useImmersiveDarkMode, sizeof(int)) == 0;
114+
}
115+
116+
return false;
117+
}
118+
119+
private static bool IsWindows10OrGreater(int build = -1)
120+
{
121+
return Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= build;
122+
}
123+
124+
// styles for dark mode
125+
Color backgroundColor = Color.FromArgb(12, 12, 12);
126+
Color foregroundColor = Color.White;
127+
Color buttonColor = Color.FromArgb(44, 44, 44);
128+
int buttonBorderSize = 0;
32129
}
33130
}

0 commit comments

Comments
 (0)