读书人

重绘lable边框解决思路

发布时间: 2012-03-17 19:06:27 作者: rapoo

重绘lable边框
重绘lable边框,结果四个边的宽度不一样;看起来上、左边是1px,下、右边是3px。
我设置的是3px,代码如下:
[code=C#][/code]Graphics a = lb.CreateGraphics();
Pen pen1 = new Pen(Color.Blue, 3);
a.DrawRectangle(pen1, 0, 0, 52, 52);

[解决办法]

C# code
    public partial class MyLabel : Label    {        public MyLabel()        {            InitializeComponent();        }        protected override void OnPaint(PaintEventArgs e)        {            base.OnPaint(e);            Rectangle rect = this.ClientRectangle;            rect.Inflate(-2, -2);            using (Pen pen = new Pen(Color.Red, 3))                e.Graphics.DrawRectangle(pen, rect);        }    }
[解决办法]
同上····原因是你画的画条左上会占用一象素,而下边就会多出一像素出来。

读书人网 >C#

热点推荐