这是我在继承ListBox时,重绘所用的代码,你可以参考一下,
protected override void OnMeasureItem ( System.Windows.Forms.MeasureItemEventArgs e )
{
e.ItemHeight = Math.Max(_drawRect.Height ,this.Font.Height) + 2;
e.ItemWidth = _drawRect.Width + 2 +
(int)e.Graphics.MeasureString(str[e.Index],this.Font).Width ;<<<--这里
}
protected override void OnMeasureItem ( System.Windows.Forms.MeasureItemEventArgs e )
{
e.ItemHeight = Math.Max(_drawRect.Height ,this.Font.Height) + 2;
e.ItemWidth = _drawRect.Width + 2 +
(int)e.Graphics.MeasureString(str[e.Index],this.Font).Width ;<<<--这里
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货