//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自定义颜色字体
listBox自定义颜色字体
最新推荐文章于 2024-08-31 16:44:41 发布