管理

当前操作系统的应用主题工具类 - C#小函数类推荐

Posted on 2025-11-10 00:32  lzhdim  阅读(0)  评论(0)    收藏  举报
/***

    当前操作系统的应用主题

    Austin Liu 刘恒辉
    Project Manager and Software Designer

    E-Mail: lzhdim@163.com
    Blog:   http://lzhdim.cnblogs.com
    Date:   2024-01-15 15:18:00

***/

namespace Lzhdim.LPF.Utility
{
    using Microsoft.Win32;

    /// <summary>
    /// 当前操作系统的应用主题
    /// </summary>
    public sealed class AppsUseLightThemeUtil
    {
        /// <summary>
        /// 是否是深色模式
        /// </summary>
        /// <returns></returns>
        public static bool IsDarkModeEnabled()
        {
            const string RegistryKeyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize";
            const string RegistryValueName = "AppsUseLightTheme";

            object registryValueObject = Registry.CurrentUser.OpenSubKey(RegistryKeyPath)?.GetValue(RegistryValueName);
            if (registryValueObject is null) return false;

            return (int)registryValueObject == 0; // 0 表示深色模式,1 表示浅色模式
        }
    }
}

 

Copyright © 2000-2022 Lzhdim Technology Software All Rights Reserved