ProgressBar进度条绘制

 Rectangle rec = new Rectangle(e.Bounds.X + 327, e.Bounds.Y, this.Width/3, this.Height);
            if (ProgressBarRenderer.IsSupported)
            {
                ProgressBarRenderer.DrawHorizontalBar(e.Graphics, rec);
            }
            //边框颜色
            Pen pen = new Pen(Color.Black, 1);
            e.Graphics.DrawRectangle(pen, rec);
            //绘制进度条空白处
            e.Graphics.FillRectangle(new SolidBrush(this.BackColor), e.Bounds.X + 327, e.Bounds.Y, rec.Width/2, rec.Height/2);

            //进度绘制
            string s = e.CellValue as string;
            string str = s; //s.Substring(0, e.CellValue.ToString().Length - 1);
            for (int i = 0; i < serverList.Count; i++)
            {
                string servername = serverList[i].name;
                if (servername == str)
                {
                    s = serverList[i].online_count_int.ToString();
                    break;
                }

            }
          // s = "10";
            decimal percent = Convert.ToDecimal(s);
            int width = (int)(100 * Math.Abs(percent / 50) * e.Bounds.Width / 50);
            Rectangle rect = new Rectangle(e.Bounds.X+327, e.Bounds.Y, width, e.Bounds.Height);
            Brush b = Brushes.Green;
            if (percent > 20)
            {
                b = Brushes.Red;
            }
           else if (percent > 10)
            {
                b = Brushes.Yellow;
            }
            e.Graphics.FillRectangle(b, rect);

posted @ 2020-05-07 17:30  学竹  阅读(341)  评论(0编辑  收藏  举报