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);
            //}
        }
     
    声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!
  • 相关阅读:
    时间复杂度
    随机数生成
    promise封装异步函数
    谷歌浏览器占用cpu过高,如何解决?
    大二层网络
    kubernetes 二进制安装部署手册
    SeaWeedfs 分布式网络文件存储介绍
    seaweedfs基本使用
    SeaweedFS基本介绍
    Linux下shell通用脚本启动jar(微服务)
  • 原文地址:https://www.cnblogs.com/lsgsanxiao/p/9371973.html
Copyright © 2011-2022 走看看