~$ 存档

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

一、重绘进度条

public class CustomProgressBar:ProgressBar
    {
        public CustomProgressBar()
        {
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            SolidBrush brush = null;
            Rectangle rec = new Rectangle(0, 0, this.Width, this.Height);

            if(ProgressBarRenderer.IsSupported)
            {
                ProgressBarRenderer.DrawHorizontalBar(e.Graphics, rec);
            }
            Pen pen = new Pen(this.ForeColor, 1);
            e.Graphics.DrawRectangle(pen, rec);
            e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 2, 2, rec.Width - 4, rec.Height - 4);

            rec.Height -= 4;
            rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4;
            brush = new SolidBrush(this.ForeColor);
            e.Graphics.FillRectangle(brush, 2, 2, rec.Width, rec.Height);
        }
    }

 

posted on 2017-08-30 16:22  LuoTian  阅读(7272)  评论(0编辑  收藏  举报