重写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 }