c# ProgressBar進度條方向和美觀


 protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.Style |= 0x04;
                return cp;
            }
        }

上面是垂直方向,從下到上

 

下面是美觀

 public class VerticalProgressBar : ProgressBar
    {
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.Style |= 0x04;
                return cp;
            }
        }

        public VerticalProgressBar()
        {
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }
        /// <summary>
        /// 從下到上 
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            SolidBrush brush = null;
            
            Rectangle rec = new Rectangle(0, 0, this.Width-1, this.Height-1);

            if (ProgressBarRenderer.IsSupported)
            {
                ProgressBarRenderer.DrawHorizontalBar(e.Graphics, rec);
            }
            //Pen pen = new Pen(this.ForeColor, 1); //左上的線色
            Pen pen = new Pen(Color.Red, 1);
            e.Graphics.DrawRectangle(pen, rec);
            //繪制進度條空白處
            e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 1, 1, rec.Width - 1, rec.Height - 1);

            rec.Width -= 1;
            rec.Height = (int)(rec.Height * ((double)Value / Maximum)) - 1;
            brush = new SolidBrush(this.ForeColor);
            //繪制進度條進度
            e.Graphics.FillRectangle(brush, 1, Height - rec.Height - 1, rec.Width, rec.Height);
        }
        /// <summary>
        /// 從左到右
        /// </summary>
        /// <param name = "e" ></ param >
        //protected override void OnPaint(PaintEventArgs e)
        //{
        //    SolidBrush brush = null;
        //    Rectangle rec = new Rectangle(0, 0, this.Width - 1, this.Height - 1);

        //    if (ProgressBarRenderer.IsSupported)
        //    {
        //        ProgressBarRenderer.DrawHorizontalBar(e.Graphics, rec);
        //    }
        //    //Pen pen = new Pen(this.ForeColor, 1); //左上的線色
        //    Pen pen = new Pen(Color.Red, 1);
        //    e.Graphics.DrawRectangle(pen, rec);
        //    e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 1, 1, rec.Width - 1, rec.Height - 1);

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

 

 
聲明:原創博客請在轉載時保留原文鏈接或者在文章開頭加上本人博客地址,如發現錯誤,歡迎批評指正。凡是轉載於本人的文章,不能設置打賞功能,如有特殊需求請與本人聯系!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM