获取System.Drawing.SystemColors类下的所有颜色

本文介绍如何将System.Drawing.SystemColors中的颜色转换为web可用的颜色格式。通过将颜色从SystemColors类提取并转换为RGB值,可以确保跨浏览器兼容性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

System.Drawing.SystemColors下的颜色主要用在windows下的窗口、菜单、文本、按钮等等使用的颜色。现在想把这些颜色使

用到web上,如果直接使用名称的话,可能有些浏览器无法识别到,因此需要将其转成标准的RGB颜色即可。。

        /// <summary>
        /// 获取SystemColors类下的所有静态颜色
        /// </summary>
        /// <returns></returns>
        public static IList<Color> GetAllColors()
        {
            Type type = typeof(SystemColors);
            PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Static);
            return props.Select(s => s.GetValue(null)).Select(s => (Color)s).ToList();
        }
        /// <summary>
        /// 获取SystemColors类下的所有静态颜色
        /// </summary>
        /// <returns></returns>
        public static IList<Color> GetAllColors()
        {
            Type type = typeof(SystemColors);
            PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Static);
            return props.Select(s => s.GetValue(null)).Select(s => (Color)s).ToList();
        }

下面是这些颜色的呈现效果

系统颜色

出自于System.Drawing.SystemColors

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值