• 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);
            //}
        }
     
    声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!
  • 相关阅读:
    [CentOS7] 安装sogou输入法
    [CentOS7] vncviewer与windows之间的复制粘贴
    linux solr7.2+tomcat8 详细部署整合
    linux solr 安装
    linux dubbo-admin-2.6.0 环境搭建
    linux tomcat安装
    linux jdk安装
    linux Nginx-1.10.2 安装部署教程
    linux技巧---创建应用快捷方式
    linux MySQL 5.7+keepalived 主备服务器自主切换
  • 原文地址:https://www.cnblogs.com/lsgsanxiao/p/9371973.html
Copyright © 2020-2023  润新知