PropertyInfo[] propInfoList = typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public);
foreach (PropertyInfo c in propInfoList)
{
this.Items.Add(c.Name);
}
this.Text = "Black"; //设置默认色
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
Rectangle rect = e.Bounds;
if (e.Index >= 0)
{
string colorName = this.Items[e.Index].ToString();
Color c = Color.FromName(colorName);
using (Brush b = new SolidBrush(c)) //预留下拉项间距
{
e.Graphics.FillRectangle(b, rect.X, rect.Y + 2, rect.Width, rect.Height - 4);
}
}
}
新闻热点
疑难解答