读书人

listBox怎么让item内容居中

发布时间: 2011-12-31 23:50:30 作者: rapoo

listBox如何让item内容居中?
listBox如何让item居中显示呢?查了半天,没找到相关资料,谢谢

[解决办法]
重载ListBox的OnDrawItem方法。

protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();

System.Drawing.StringFormat strFmt = new System.Drawing.StringFormat(System.Drawing.StringFormatFlags.NoClip);
strFmt.Alignment = System.Drawing.StringAlignment.Center;

e.Graphics.DrawString(this.Items[e.Index].Text, e.Font, new System.Drawing.SolidBrush(e.ForeColor), e.Bounds, strFmt);

base.OnDrawItem(e);
}

读书人网 >C#

热点推荐