private void PaintControl(Graphics g, Rectangle clipRectangle) { if ( g == null ) return; if ( clipRectangle == null || clipRectangle.IsEmpty ) return; float distRing1 = -(this.Width * 5) / 100; // 5% float distRing2 = -(this.Width * 10) / 100; // 10% float distArcRing = -(this.Width * 4) / 100; // 4% float distInnerCircle = -(this.Width * 30) / 100; // 30% RectangleF externalRing1 = RectangleF.Inflate(this.ClientRectangle, distRing1, distRing1); RectangleF externalRing2 = RectangleF.Inflate(this.ClientRectangle, distRing2, distRing2); RectangleF innerEllipseRing = RectangleF.Inflate(this.ClientRectangle, distInnerCircle, distInnerCircle); RectangleF progressArcRing = RectangleF.Inflate(this.ClientRectangle, distArcRing, distArcRing); using ( var smoothDrawing = new SmoothDrawing(g) ) using ( var progressCircleBrush = new SolidBrush(ProgressColor) ) { // Set smooth drawing g.SmoothingMode = SmoothingMode.AntiAlias; // Paint inner circular progress PaintProgress(g, progressCircleBrush, innerEllipseRing, externalRing2); // Draw progress arc using ( var penProgressArc = new Pen(ProgressColor, 3.0f) ) { float progressAngle = 0; if ( Style == ProgressBarStyle.Marquee ) progressAngle = 360 * CalcScaledValue(_marqueeValue); else progressAngle = 360 * ScaledValue; try { g.DrawArc(penProgressArc, progressArcRing, 270, progressAngle); } catch { } } // Draw the circular extenal ring using ( GraphicsPath p1 = new GraphicsPath() ) { p1.AddEllipse(externalRing1); using ( Region r1 = new Region(p1) ) using ( GraphicsPath p2 = new GraphicsPath() ) { p2.AddEllipse(externalRing2); r1.Exclude(p2); g.FillRegion(Brushes.WhiteSmoke, r1); } } // Draw the ring border g.DrawEllipse(Pens.White, externalRing1); g.DrawEllipse(Pens.White, externalRing2); // Draw the inner Ellipse g.FillEllipse(Brushes.WhiteSmoke, innerEllipseRing); g.DrawEllipse(Pens.White, innerEllipseRing); if ( Style != ProgressBarStyle.Marquee ) { // Draw the the progress percent using ( System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat() ) { g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; drawFormat.Alignment = StringAlignment.Center; drawFormat.LineAlignment = StringAlignment.Center; string percentString = this.Value.ToString() + "%"; g.DrawString(percentString, this.Font, progressCircleBrush, this.ClientRectangle, drawFormat); } } } }
private void PaintControl(Graphics g, Rectangle clipRectangle) { if (g == null) { return; } if (clipRectangle == null || clipRectangle.IsEmpty) { return; } float distRing1 = -(this.Width * 5) / 100; // 5% float distRing2 = -(this.Width * 10) / 100; // 10% float distArcRing = -(this.Width * 4) / 100; // 4% float distInnerCircle = -(this.Width * 30) / 100; // 30% RectangleF externalRing1 = RectangleF.Inflate(this.ClientRectangle, distRing1, distRing1); RectangleF externalRing2 = RectangleF.Inflate(this.ClientRectangle, distRing2, distRing2); RectangleF innerEllipseRing = RectangleF.Inflate(this.ClientRectangle, distInnerCircle, distInnerCircle); RectangleF progressArcRing = RectangleF.Inflate(this.ClientRectangle, distArcRing, distArcRing); using (var smoothDrawing = new SmoothDrawing(g)) using (var progressCircleBrush = new SolidBrush(ProgressColor)) { // Set smooth drawing g.SmoothingMode = SmoothingMode.AntiAlias; // Paint inner circular progress PaintProgress(g, progressCircleBrush, innerEllipseRing, externalRing2); // Draw progress arc using (var penProgressArc = new Pen(ProgressColor, 3.0f)) { float progressAngle = 0; if (Style == ProgressBarStyle.Marquee) { progressAngle = 360 * CalcScaledValue(_marqueeValue); } else { progressAngle = 360 * ScaledValue; } try { g.DrawArc(penProgressArc, progressArcRing, 270, progressAngle); } catch { } } // Draw the circular extenal ring using (GraphicsPath p1 = new GraphicsPath()) { p1.AddEllipse(externalRing1); using (Region r1 = new Region(p1)) using (GraphicsPath p2 = new GraphicsPath()) { p2.AddEllipse(externalRing2); r1.Exclude(p2); g.FillRegion(Brushes.WhiteSmoke, r1); } } // Draw the ring border g.DrawEllipse(Pens.White, externalRing1); g.DrawEllipse(Pens.White, externalRing2); // Draw the inner Ellipse g.FillEllipse(Brushes.WhiteSmoke, innerEllipseRing); g.DrawEllipse(Pens.White, innerEllipseRing); if (Style != ProgressBarStyle.Marquee) { // Draw the the progress percent using (System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat()) { g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; drawFormat.Alignment = StringAlignment.Center; drawFormat.LineAlignment = StringAlignment.Center; string percentString = this.Value.ToString() + "%"; g.DrawString(percentString, this.Font, progressCircleBrush, this.ClientRectangle, drawFormat); } } } }