首页 > 其他 > 详细

控件重绘

时间:2017-05-08 09:29:54      阅读:230      评论:0      收藏:0      [点我收藏+]

1. 设置控件DrawMode属性为OwnerDrawFixed,编辑控件DrawItem事件

 

重绘tabControl——选项卡控件

    string text = ((TabControl)sender).TabPages[e.Index].Text;
    SolidBrush brush = new SolidBrush(Color.Black);
    StringFormat sf = new StringFormat(StringFormatFlags.DirectionRightToLeft);
    sf.LineAlignment = StringAlignment.Center;
    sf.Alignment = StringAlignment.Center;
    e.Graphics.DrawString(text, SystemInformation.MenuFont, brush, e.Bounds, sf);

重绘listBox控件(注意修改涉及控件名的地方)

    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(listBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), rf);

控件重绘

原文:http://www.cnblogs.com/zhangchaoran/p/6823274.html

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