首页 > 其他 > 详细

007. 自定义ListBox的item的宽高, 字体居中

时间:2016-11-21 14:46:10      阅读:205      评论:0      收藏:0      [点我收藏+]
 /// <summary>
        /// 自定义ListBox的item的宽高, 字体居中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lisB_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
            {
                return;
            }
            e.DrawBackground(); //绘制各项的背景色
            e.DrawFocusRectangle(); 
            //让文字位于Item的中间
            float difH = (e.Bounds.Height - e.Font.Height) / 2;
            //指定绘制文本的位置
            RectangleF rf = new RectangleF(e.Bounds.X, e.Bounds.Y + difH, e.Bounds.Width, e.Font.Height);
            //绘制指定的字符串
            e.Graphics.DrawString(lisB.Items[e.Index].ToString(), e.Font, new SolidBrush(Color.Black), rf);
        }

        private void lisB_MeasureItem(object sender, MeasureItemEventArgs e)
        {
          //if(e.Index==1)  指定某一行的高度
                e.ItemHeight = 22;
        }

 

007. 自定义ListBox的item的宽高, 字体居中

原文:http://www.cnblogs.com/wxylog/p/6085275.html

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