重写ListBox.DrawItem事件处理,别忘记将ListBox.DrawMode 设置为OwnerDrawVariable,ListBox.ItemHeight值改大一点,字体也适当放大一号。

 1         private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
 2         {
 3             e.DrawBackground();
 4 
 5             e.DrawFocusRectangle();
 6 
 7             StringFormat strFmt = new System.Drawing.StringFormat();
 8 
 9             strFmt.Alignment = StringAlignment.Near; //文本水平居中
10 
11             strFmt.LineAlignment = StringAlignment.Center; //文本垂直居中
12 
13             e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds, strFmt);
14         }

相关文章:

  • 2021-05-28
  • 2022-12-23
  • 2021-06-20
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
  • 2021-10-12
  • 2021-10-05
  • 2022-02-10
  • 2022-12-23
相关资源
相似解决方案