- The first thing to do is to set the control's DrawMode property to OwnerDrawVariable
- Add DrawItem Redraw event: private void Listbox1_drawitem (object sender, DrawItemEventArgs e)
{
E.drawbackground ();
E.drawfocusrectangle ();
StringFormat strfmt = new System.Drawing.StringFormat ();
Strfmt.alignment = Stringalignment.center; Text is centered vertically
Strfmt.linealignment = Stringalignment.center; Text is centered horizontally
E.graphics.drawstring (Listbox1.items[e.index]. ToString (), E.font, New SolidBrush (E.forecolor), e.bounds, strfmt);
}
- Set row height: Set the height value you want in the ItemHeight property, which is larger than the font height, which is originally the font height. If the DrawMode property is not ownerdrawvariable, ItemHeight cannot be modified.
Adjust the row spacing of a ListBox control and format text