Yassine_Abbani

Ring [Progressbar], [Custom Control]

May 23rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.24 KB | None | 0 0
  1. #region Derectives
  2. using System;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.Drawing.Text;
  7. using System.Windows.Forms;
  8. #endregion
  9.  
  10. #region Browse
  11. /* Copyright & Contact
  12. * --------------------------------------------------------------------------------<
  13. * Tool Name    : ProgressBar                                                     *
  14. * From Project : Creator Eye                                                      *
  15. * Project Lang : C#                                                               *
  16. * Creator      : Yassine Abbani                                                   *
  17. * Facebook     : https://www.facebook.com/YassineAbbani.user                      *
  18. * Pastebin     : https://pastebin.com/u/Yassine_Abbani                            *
  19. * Youtube      : https://www.youtube.com/channel/UCqvOCRs3HWbPH4yuZuTx8mw         *
  20. * Version      : 1.0 Beta                                                         *
  21. * Color        : Blue, Dark Theme                                                 *
  22. * Style        : Ring                                                         *
  23. *>--------------------------------------------------------------------------------<
  24. */
  25. /* Features
  26. * ------------------------
  27. *   Custom Properties:
  28.  *   Create Circular Style.
  29.  *   add the range specified by minimum and maximum value.
  30.  *   Using  Relative Value Style
  31. */
  32. /*  history
  33. * ------------------------
  34. * 1.0 (20 Feb 2018):
  35.  * In my Source Code Get Ring progress-bar Like Gmail Style with Great Effect.
  36.  * So, in this case,you can use this controller as Circular Progress Bar with input Or edit value, and maximum value.
  37. *
  38. */
  39. #endregion
  40. #region
  41. public class Ce_CircularProgressBar : Control
  42. {
  43.     private float P = 10;
  44.  
  45.     #region  Properties
  46.     [Description("The current percentage for the ProgressBar, in the range specified by minimum and maximum"), Category("Behavior")]
  47.     public float Percentage
  48.     {
  49.         get { return P; }
  50.         set
  51.         {
  52.             P = value;
  53.             Invalidate();
  54.         }
  55.     }
  56.  
  57.     [Browsable(false)]
  58.     public bool AllowDrop
  59.     {
  60.         get { return base.AllowDrop; }
  61.         set { base.AllowDrop = value; }
  62.     }
  63.     [Browsable(false)]
  64.     public ImeMode ImeMode
  65.     {
  66.         get { return base.ImeMode; }
  67.         set { base.ImeMode = value; }
  68.     }
  69.     #endregion
  70.     #region Constructors
  71.     public Ce_CircularProgressBar()
  72.     {
  73.         Font = new Font("Roboto", 10);
  74.         DoubleBuffered = true;
  75.     }
  76.     #endregion
  77.     #region Draw Control
  78.     protected override void OnPaint(PaintEventArgs e)
  79.     {
  80.         base.OnPaint(e);
  81.  
  82.         Width = 71;
  83.         Height = 71;
  84.  
  85.         Rectangle rect = new Rectangle(5, 5, 60, 60);
  86.         Graphics g = e.Graphics;
  87.         float percentage;
  88.  
  89.         if (Percentage <= 100 && Percentage >= 0)
  90.         {
  91.             percentage = P;
  92.         }
  93.         else
  94.         {
  95.             percentage = 10;
  96.             Percentage = 10;
  97.             MessageBox.Show("Wrong value...!", "Chek Creators Eye Website", MessageBoxButtons.OK, MessageBoxIcon.Information);
  98.         }
  99.  
  100.         dynamic progressAngle = Convert.ToSingle((percentage * 360) / 100);
  101.         dynamic remainderAngle = 360 - progressAngle;
  102.  
  103.         using (Pen progressPen = new Pen(new SolidBrush(Color.FromArgb(110, 161, 252)), 3))
  104.         {
  105.             using (Pen remainderPen = new Pen(Color.LightGray, 3))
  106.             {
  107.                 g.SmoothingMode = SmoothingMode.AntiAlias;
  108.                 g.DrawArc(progressPen, rect, -90, progressAngle);
  109.                 g.DrawArc(remainderPen, rect, progressAngle - 90, remainderAngle);
  110.             }
  111.         }
  112.  
  113.         using (Font fnt = new Font("Roboto", 14))
  114.         {
  115.             string text = percentage.ToString() + "%";
  116.             dynamic textSize = g.MeasureString(text, fnt);
  117.             Point textPoint = new Point(Convert.ToInt32(rect.Left + (rect.Width / 2) - (textSize.Width / 2)), Convert.ToInt32(rect.Top + (rect.Height / 2) - (textSize.Height / 2)));
  118.  
  119.             g.TextRenderingHint = TextRenderingHint.AntiAlias;
  120.             g.DrawString(text, fnt, new SolidBrush(Color.FromArgb(172, 172, 172)), textPoint);
  121.         }
  122.     }
  123.     #endregion
  124. }
  125. #endregion
Add Comment
Please, Sign In to add comment