예제 #1
0
        private void DrawProgress(Point pt, int count, int total, string text)
        {
            Graphics g        = CreateGraphics();
            DpiScale dpiScale = new DpiScale(g);
            int      offsetX  = dpiScale.ScaleIntX(1);
            int      offsetY  = dpiScale.ScaleIntY(1);

            int       height = Height - offsetY;
            int       width  = Width - offsetX;
            Pen       pen    = new Pen(Color.Black, 1.0f);
            Rectangle rect   = new Rectangle(pt, new Size(width, height));

            g.DrawRectangle(pen, rect);

            double percent = 0;

            if (total > 0)
            {
                percent = count / (double)total;
            }

            width = Width - offsetX;
            if (total != 0)
            {
                width = (int)(width * percent);
            }

            pt.Offset(offsetX, offsetY);
            rect = new Rectangle(pt, new Size(rect.Width - offsetX, rect.Height - offsetY));
            Brush     bgBrush     = new LinearGradientBrush(rect, Color.DarkGray, Color.LightGray, 90.0f);
            Rectangle percentRect = new Rectangle(rect.Location, new Size(width, rect.Height));
            Brush     brush       = GetPercentBrush(rect, percent, total);

            g.FillRectangle(bgBrush, rect);
            if (width > 0)
            {
                g.FillRectangle(brush, percentRect);
                pt.Offset(-offsetX, -offsetY);
                g.DrawRectangle(GetPrecentPen(percent, total), new Rectangle(pt, new Size(percentRect.Width + offsetX, percentRect.Height + offsetY)));
            }

            SizeF  size     = g.MeasureDisplayString(text, DisplayFont);
            var    offset   = (height - size.Height) / 2;
            PointF position = new PointF(pt.X + dpiScale.ScaleIntX(8), pt.Y + offset + dpiScale.ScaleFloatY(2.5f));

            g.DrawString(text, DisplayFont, FontBrush, position);
        }
예제 #2
0
        private void DrawProgress(Point pt, int count, int total, string text)
        {
            Graphics g        = CreateGraphics();
            DpiScale dpiScale = new DpiScale(g);
            int      offsetX  = dpiScale.ScaleIntX(1);
            int      offsetY  = dpiScale.ScaleIntY(1);

            int       height = Height - offsetX;
            int       width  = Width - offsetY;
            Pen       pen    = new Pen(Color.Black, 1.0f);
            Rectangle rect   = new Rectangle(pt, new Size(width, height));

            g.DrawRectangle(pen, rect);

            double percent = 0;

            if (total > 0)
            {
                percent = count / (double)total;
            }
            width = (int)((Width - offsetX) * percent);

            pt.Offset(offsetX, offsetY);
            rect = new Rectangle(pt, new Size(rect.Width - offsetX, rect.Height - offsetY));
            Brush     bgBrush     = new LinearGradientBrush(rect, Color.DarkGray, Color.LightGray, 90.0f);
            Rectangle percentRect = new Rectangle(rect.Location, new Size(width, rect.Height));
            Brush     brush       = GetPercentBrush(rect, percent);

            g.FillRectangle(bgBrush, rect);
            if (percent > 0)
            {
                g.FillRectangle(brush, percentRect);
                pt.Offset(-offsetX, -offsetY);
                g.DrawRectangle(GetPrecentPen(percent), new Rectangle(pt, new Size(percentRect.Width + offsetX, percentRect.Height + offsetY)));
            }

            Brush  fontBrush = new SolidBrush(Color.Black);
            PointF position  = new PointF(pt.X + dpiScale.ScaleIntX(8), pt.Y + dpiScale.ScaleFloatY(2.5f));

            g.DrawString(text, new Font(FontFamily.GenericSerif, 10.0f, FontStyle.Bold), fontBrush, position);
        }