首页 > 其他 > 详细

调整ListBox控件的行间距及设置文本格式

时间:2015-07-15 09:18:45      阅读:480      评论:0      收藏:0      [点我收藏+]
  1. 首先要将该控件的DrawMode属性为OwnerDrawVariable
  2. 添加DrawItem重绘事件:private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
    {
    e.DrawBackground();
    e.DrawFocusRectangle();
    StringFormat strFmt = new System.Drawing.StringFormat();
    strFmt.Alignment = StringAlignment.Center; //文本垂直居中
    strFmt.LineAlignment = StringAlignment.Center; //文本水平居中
    e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds, strFmt);
    }
  3. 设置行高:在ItemHeight属性中设置你想要的高度值 ,大于字体高度即可,原先默认为字体高度。DrawMode属性若不是为OwnerDrawVariable,则ItemHeight无法修改。

调整ListBox控件的行间距及设置文本格式

原文:http://www.cnblogs.com/enjoyprogram/p/4647318.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!