AutoCAD C# 自动控制CAD主题颜色跟随系统

 private static void ConfigureAutoCADThemeAsWindowsTheme()
 {
     var COLORTHEME = (short)Application.GetSystemVariable("COLORTHEME");
     const string RegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
     const string RegistryValueName = "AppsUseLightTheme";
     // 这里也可能是LocalMachine(HKEY_LOCAL_MACHINE)
     // see "https://www.addictivetips.com/windows-tips/how-to-enable-the-dark-theme-in-windows-10/"
     object? registryValueObject = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(RegistryKeyPath)?.GetValue(RegistryValueName);
     bool curSysThemeIsBlack;
     if (registryValueObject is null) curSysThemeIsBlack = false;
     curSysThemeIsBlack = (int)registryValueObject <= 0;
     if (curSysThemeIsBlack)
     {
         if (COLORTHEME != 0)
             Application.SetSystemVariable("COLORTHEME", 0);
     }
     else
     {
         if (COLORTHEME != 1)
             Application.SetSystemVariable("COLORTHEME", 1);
     }
 }

 

posted @ 2025-02-26 21:20  南胜NanSheng  阅读(43)  评论(1)    收藏  举报