Advertisement
Yassine_Abbani

Circular [Progress Bar], [Costume Control]

May 14th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 KB | None | 0 0
  1. #region Import
  2. using System;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Drawing.Text;
  8. using System.Windows.Forms;
  9. #endregion
  10. #region Copyright & Contact
  11. // Creator: Cheat Eye
  12. // CEO: Yassine Abbani
  13. // Link: https://www.facebook.com/yassineabbani
  14. // Version: 1.0.0
  15. #endregion
  16.  
  17.  
  18.  
  19.  
  20. #region  CircularProgressBar
  21. public class BlueCircularProgressBar : Control
  22. {
  23.     private float P = 10;
  24.  
  25.     #region  Properties
  26.     [Description("The current Value for the ProgressBar, in the range specified by minimum and maximum"), Category("Behavior")]
  27.     public float Value
  28.     {
  29.         get { return P; }
  30.         set
  31.         {
  32.             P = value;
  33.             Invalidate();
  34.         }
  35.     }
  36.  
  37.     [Browsable(false)]
  38.     public bool AllowDrop
  39.     {
  40.         get { return base.AllowDrop; }
  41.         set { base.AllowDrop = value; }
  42.     }
  43.     [Browsable(false)]
  44.     public ImeMode ImeMode
  45.     {
  46.         get { return base.ImeMode; }
  47.         set { base.ImeMode = value; }
  48.     }
  49.     #endregion
  50.  
  51.     public BlueCircularProgressBar()
  52.     {
  53.         Font = new Font("Roboto", 10);
  54.         DoubleBuffered = true;
  55.     }
  56.  
  57.     protected override void OnPaint(PaintEventArgs e)
  58.     {
  59.         base.OnPaint(e);
  60.  
  61.         Width = 71;
  62.         Height = 71;
  63.  
  64.         Rectangle rect = new Rectangle(5, 5, 60, 60);
  65.         Graphics g = e.Graphics;
  66.         float percentage;
  67.  
  68.         if (Value <= 100 && Value >= 0)
  69.         {
  70.             percentage = P;
  71.         }
  72.         else
  73.         {
  74.             percentage = 10;
  75.             Value = 10;
  76.             MessageBox.Show("Wrong value...!", "Blue Theme", MessageBoxButtons.OK, MessageBoxIcon.Information);
  77.         }
  78.  
  79.         dynamic progressAngle = Convert.ToSingle((percentage * 360) / 100);
  80.         dynamic remainderAngle = 360 - progressAngle;
  81.  
  82.         using (Pen progressPen = new Pen(new SolidBrush(Color.FromArgb(110, 161, 252)), 3))
  83.         {
  84.             using (Pen remainderPen = new Pen(Color.FromArgb(91, 110, 144)))
  85.             {
  86.                 g.SmoothingMode = SmoothingMode.AntiAlias;
  87.                 g.DrawArc(progressPen, rect, -90, progressAngle);
  88.                 g.DrawArc(remainderPen, rect, progressAngle - 90, remainderAngle);
  89.             }
  90.         }
  91.  
  92.         using (Font fnt = new Font("Roboto", 14))
  93.         {
  94.             string text = percentage.ToString() + "%";
  95.             dynamic textSize = g.MeasureString(text, fnt);
  96.             Point textPoint = new Point(Convert.ToInt32(rect.Left + (rect.Width / 2) - (textSize.Width / 2)), Convert.ToInt32(rect.Top + (rect.Height / 2) - (textSize.Height / 2)));
  97.  
  98.             g.TextRenderingHint = TextRenderingHint.AntiAlias;
  99.             g.DrawString(text, fnt, new SolidBrush(Color.FromArgb(37, 150, 255)), textPoint);
  100.         }
  101.     }
  102. }
  103. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement