//控制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);

            }
        }

 

相关文章:

  • 2022-02-10
  • 2021-07-12
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2021-05-11
  • 2022-12-23
猜你喜欢
  • 2021-05-11
  • 2021-03-31
  • 2021-09-04
  • 2021-05-27
  • 2021-08-12
相关资源
相似解决方案