|
1 | | -using System; |
| 1 | +using Microsoft.Win32; |
| 2 | +using System; |
| 3 | +using System.Drawing; |
| 4 | +using System.Globalization; |
| 5 | +using System.Runtime.InteropServices; |
2 | 6 | using System.Windows.Forms; |
3 | 7 |
|
4 | 8 | namespace imageResizer |
5 | 9 | { |
6 | 10 | public partial class AboutBox : Form |
7 | 11 | { |
| 12 | + internal Options Options { get; set; } |
| 13 | + |
8 | 14 | public AboutBox() |
9 | 15 | { |
10 | 16 | InitializeComponent(); |
11 | 17 | } |
12 | 18 |
|
13 | | - private void buttonOK_Click(object sender, EventArgs e) |
| 19 | + private void ButtonOK_Click(object sender, EventArgs e) |
14 | 20 | { |
15 | 21 | this.Close(); |
16 | 22 | } |
17 | 23 |
|
18 | | - private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) |
| 24 | + private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) |
19 | 25 | { |
20 | 26 | System.Diagnostics.Process.Start("https://github.com/borisonekenobi/"); |
21 | 27 | } |
22 | 28 |
|
23 | | - private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) |
| 29 | + private void LinkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) |
24 | 30 | { |
25 | 31 | System.Diagnostics.Process.Start("mailto:borisonekenobi@gmail.com"); |
26 | 32 | } |
27 | 33 |
|
28 | 34 | private void AboutBox_Load(object sender, EventArgs e) |
29 | 35 | { |
| 36 | + UpdateTheme(); |
30 | 37 | label5.Text = "Current: v" + Form1.CurrentVersion + "\nLatest: v" + Form1.LatestVersion; |
31 | 38 | } |
| 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; |
32 | 129 | } |
33 | 130 | } |
0 commit comments