zoukankan      html  css  js  c++  java
  • 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);
            //}
        }
     
    声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!
  • 相关阅读:
    「学习笔记」杂项算法学习笔记
    「CF484E」Sign on Fence「整体二分」「线段树」
    「BZOJ 2653」middle「主席树」「二分」
    「BZOJ 5010」「FJOI 2017」矩阵填数「状压DP」
    jmeter阶梯式加压测试
    jmeter监控内存,CPU等方法
    jmeter 读取多个用户名并同时发
    APP性能测试工具
    Android--iOS抓取崩溃日志
    安装并使用PICT,生成测试用例
  • 原文地址:https://www.cnblogs.com/lsgsanxiao/p/9371973.html
Copyright © 2011-2022 走看看