日期:2014-05-20 浏览次数:20993 次
private void Form1_Load(object sender, EventArgs e) { listBox1.Items.Add("红色"); listBox1.Items.Add("黄色"); listBox1.Items.Add("蓝色"); listBox1.DrawMode = DrawMode.OwnerDrawFixed; // 属性里设置 } private void listBox1_DrawItem(object sender, DrawItemEventArgs e) { Color vColor = e.ForeColor; switch (e.Index) { case 0: vColor = Color.Red; break; case 1: vColor = Color.Yellow; break; case 2: vColor = Color.Blue; break; } e.Graphics.FillRectangle(new SolidBrush(vColor), e.Bounds); e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds); e.DrawFocusRectangle(); }