c# - 列出所有系统颜色

标签 c# gdi+ systemcolors

在 Windows.Forms 中,我需要创建一个接受任何颜色并尝试找到与之对应的系统颜色的程序。

我无法弄清楚如何遍历 System.Drawing.SystemColors 类的所有颜色 - 它是一个类,而不是枚举或列表。

我该怎么做(某种反射?)?

最佳答案

怎么样

public static Dictionary<string,object> GetStaticPropertyBag(Type t)
{
    const BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

    var map = new Dictionary<string, object>();
    foreach (var prop in t.GetProperties(flags))
    {
        map[prop.Name] = prop.GetValue(null, null);
    }
    return map;
}

foreach (System.Reflection.PropertyInfo prop in typeof(SystemColors).GetProperties())
{
     if (prop.PropertyType.FullName == "System.Drawing.Color")
         ColorComboBox.Items.Add(prop.Name);
}

关于c# - 列出所有系统颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12329138/

相关文章:

c# - DrawPath 和 DrawRectangle 的区别

graphics - GDI+中是否有等效的软笔?

asp.net - aspNetDisabled 类默认系统颜色

.net - 在.NET中获取Windows XP颜色

C# WPF按钮链接到用户控制页面

c# - 改变数字 updown 的高度

c# - Form.FormBorderStyle native 异常访问冲突

c# - 即使我将其丢弃,TextureBrush 也会导致内存泄漏

基于 SystemColors 的 WPF 通用颜色

c# - 无法确定类型为 > 'System.Data.SqlClient.SqlClientFactory' 的提供程序工厂的提供程序名称