private void _listBox_MeasureItem ( object sender, MeasureItemEventArgs e ) { int index = e.Index; if ((index >= 0) || (index < _listBox.Items.Count)) { ChooseInfo chooseInfo = (ChooseInfo)_listBox.Items[index]; string text = chooseInfo.ToString(); SizeF size = e.Graphics.MeasureString(text, _listBox.Font, _listBox.ClientSize.Width); e.ItemWidth = (int)size.Width; e.ItemHeight = (int)size.Height + 4; } }
private void _listBox_DrawItem ( object sender, DrawItemEventArgs e ) { int index = e.Index; e.DrawBackground(); if ((index >= 0) || (index < _listBox.Items.Count)) { ChooseInfo chooseInfo = (ChooseInfo)_listBox.Items[index]; string text = chooseInfo.ToString(); //SizeF size = e.Graphics.MeasureString(text, _listBox.Font, // _listBox.ClientSize.Width); using (Brush brush = new SolidBrush(e.ForeColor)) { Rectangle bounds = e.Bounds; bounds.Inflate(-1, -2); e.Graphics.DrawString(text, e.Font, brush, bounds); } } e.DrawFocusRectangle(); }