ThemeManager.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Microsoft.Win32;
  2. using System.Drawing;
  3. namespace quick_color_picker
  4. {
  5. class ThemeManager
  6. {
  7. public static Color MainColorDark = Color.Black;
  8. public static Color BackColorDark = Color.FromArgb(32, 32, 32);
  9. public static Color SecondColorDark = Color.FromArgb(51, 51, 51);
  10. public static Color AccentColorDark = Color.FromArgb(110, 110, 110);
  11. public static bool isDarkTheme()
  12. {
  13. if (isWindows10())
  14. {
  15. string root = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
  16. string str = Registry.GetValue(root, "AppsUseLightTheme", null).ToString();
  17. return (str == "0");
  18. }
  19. else
  20. {
  21. return false;
  22. }
  23. }
  24. public static bool isWindows10()
  25. {
  26. var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
  27. string productName = (string)reg.GetValue("ProductName");
  28. return productName.StartsWith("Windows 10");
  29. }
  30. public static Color getColorizationColor()
  31. {
  32. if (isWindows10())
  33. {
  34. string root = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\DWM";
  35. string colorcode = Registry.GetValue(root, "ColorizationColor", null).ToString();
  36. return System.Drawing.ColorTranslator.FromHtml(colorcode);
  37. }
  38. else
  39. {
  40. return Color.Blue;
  41. }
  42. }
  43. public static Color getAccentColor()
  44. {
  45. if (isWindows10())
  46. {
  47. string root = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\DWM";
  48. string colorcode = Registry.GetValue(root, "AccentColor", null).ToString();
  49. return System.Drawing.ColorTranslator.FromHtml(colorcode);
  50. }
  51. else
  52. {
  53. return Color.White;
  54. }
  55. }
  56. }
  57. }