知行合一

享受过程 漠视结果

导航

控制listbox的字体颜色

        //控制listbox的字体颜色
        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            if (e.Index > -1)
            {
                SolidBrush brsr = new SolidBrush(Color.Red);
                SolidBrush brsg = new SolidBrush(Color.Green);
                SolidBrush brsb = new SolidBrush(Color.Blue);
                if (e.Index % 2 == 0)
                    e.Graphics.DrawString(Convert.ToString(listBox1.Items[e.Index]), e.Font, brsr, e.Bounds);
                //else if (e.Index % 3 == 0)
                //    e.Graphics.DrawString(Convert.ToString(listBox1.Items[e.Index]), e.Font, brsg, e.Bounds);
                else
                    e.Graphics.DrawString(Convert.ToString(listBox1.Items[e.Index]), e.Font, brsb, e.Bounds);

            }
        }

 

posted on 2010-11-17 16:10  项羽  阅读(957)  评论(0编辑  收藏  举报