您的位置:首页 > 其它

listBox自定义颜色字体

2011-10-06 09:28 302 查看
//listBox自定义颜色字体
System.Collections.Generic.Dictionary<string, Color> colorItems = new System.Collections.Generic.Dictionary<string, Color>();
private void Form1_Load(object sender, EventArgs e)
{
colorItems.Add("红色", Color.Red);
colorItems.Add("绿色", Color.Green);
colorItems.Add("蓝色", Color.Blue);
foreach (string vKey in colorItems.Keys)
listBox显示.Items.Add(vKey);
listBox显示.DrawMode = DrawMode.OwnerDrawFixed; // 属性里设置
}
private void listBox显示_DrawItem(object sender, DrawItemEventArgs e)
{
string vKey = ((ListBox)sender).Items[e.Index].ToString();
e.DrawBackground();
e.Graphics.DrawString(vKey, e.Font, new SolidBrush(colorItems[vKey]), e.Bounds);
e.DrawFocusRectangle();
}
//listBox自定义颜色字体
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: