获取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

private void Form2_Load(object sender, EventArgs e) { try { connection.Open(); string query = @" SELECT N.Name AS StudentName, G.GroupName, S.TotalScore, S.BonusPoints, S.PenaltyPoints FROM ((Names N INNER JOIN Scores S ON N.ID = S.StudentID) INNER JOIN Groups G ON S.GroupID = G.GroupID) WHERE N.ID = @studentId"; OleDbCommand command = new OleDbCommand(query, connection); command.Parameters.AddWithValue("@studentId", studentId); OleDbDataReader reader = command.ExecuteReader(); if (reader.Read()) { Label nameLabel = new Label { Text = $"姓名: {reader["StudentName"]}", Location = new System.Drawing.Point(50, 50) }; Label groupLabel = new Label { Text = $"组别: {reader["GroupName"]}", Location = new System.Drawing.Point(50, 80) }; Label totalScoreLabel = new Label { Text = $"总分: {reader["TotalScore"]}", Location = new System.Drawing.Point(50, 110) }; TextBox bonusTextBox = new TextBox { PlaceholderText = "加分", Location = new System.Drawing.Point(50, 140), Width = 100 }; TextBox penaltyTextBox = new TextBox { PlaceholderText = "扣分", Location = new System.Drawing.Point(50, 170), Width = 100 }; Button updateButton = new Button { Text = "更新分数", Location = new System.Drawing.Point(50, 200) }; updateButton.Click += UpdateScore_Click; Controls.AddRange(new Control[] { nameLabel, groupLabel, totalScoreLabel, bonusTextBox, penaltyTextBox, updateButton }); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } } 严重性 代码 说明 项目 文件 行 禁止显示状态 详细信息 错误(活动) CS0117 “TextBox”未包含“PlaceholderText”的定义 ClassPerformances E:\YEUNGSSTUDIO\C#学习\Class\ClassPerformances\Form2.cs 46 改进代码
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值