Advertisement
Yassine_Abbani

Glass [Progress Bar], [Costume Control]

May 11th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.23 KB | None | 0 0
  1.     #region Imports
  2.  
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Drawing;
  8. using System.Drawing.Drawing2D;
  9. using System.Drawing.Text;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using System.Windows.Forms;
  13. using System.IO;
  14. using System.Drawing.Imaging;
  15. using System.Linq;
  16.  
  17. #endregion
  18.     #region Copyright & contact
  19. // Creator : Yassine Abbani
  20. // Facebook : https://www.facebook.com/yassineabbani.user
  21. // Youtube  : https://www.youtube.com/channel/UCqvOCRs3HWbPH4yuZuTx8mw
  22. // website  : Null
  23. // Pastebin  : https://pastebin.com/u/Yassine_Abbani
  24. #endregion
  25.     #region Glass ProgreSsBar
  26. class Ce_GlassProgreSsBar : Control
  27. {
  28.     private System.Windows.Forms.Timer GlowAnimation = new System.Windows.Forms.Timer();
  29.     //Private _GlowColor As Color = Color.FromArgb(55, 65, 75)
  30.     private Color _GlowColor = Color.FromArgb(50, 255, 255, 255);
  31.     private bool _Animate = true;
  32.     private Int32 _Value = 0;
  33.     private Color _HighlightColor = Color.Silver;
  34.     private Color _BackgroundColor = Color.FromArgb(150, 150, 150);
  35.     #region "Properties"
  36.     private Color _StartColor = Color.FromArgb(110, 110, 110);
  37.     public Color Color
  38.     {
  39.         get { return _StartColor; }
  40.         set
  41.         {
  42.             _StartColor = value;
  43.             this.Invalidate();
  44.         }
  45.     }
  46.     public bool Animate
  47.     {
  48.         get { return _Animate; }
  49.         set
  50.         {
  51.             _Animate = value;
  52.             if (value == true)
  53.             {
  54.                 GlowAnimation.Start();
  55.             }
  56.             else
  57.             {
  58.                 GlowAnimation.Stop();
  59.             }
  60.             this.Invalidate();
  61.         }
  62.     }
  63.     public Color GlowColor
  64.     {
  65.         get { return _GlowColor; }
  66.         set
  67.         {
  68.             _GlowColor = value;
  69.             this.Invalidate();
  70.         }
  71.     }
  72.     public Int32 Value
  73.     {
  74.         get { return _Value; }
  75.         set
  76.         {
  77.             if (value < 0)
  78.                 return;
  79.             _Value = value;
  80.             if (value < 100)
  81.                 GlowAnimation.Start();
  82.  
  83.             this.Invalidate();
  84.         }
  85.     }
  86.     public Color BackgroundColor
  87.     {
  88.         get { return _BackgroundColor; }
  89.         set
  90.         {
  91.             _BackgroundColor = value;
  92.             this.Invalidate();
  93.         }
  94.     }
  95.     public Color HighlightColor
  96.     {
  97.         get { return _HighlightColor; }
  98.         set
  99.         {
  100.             _HighlightColor = value;
  101.             this.Invalidate();
  102.         }
  103.     }
  104.  
  105.     #endregion
  106.     private bool InDesignMode()
  107.     {
  108.         return (LicenseManager.UsageMode == LicenseUsageMode.Designtime);
  109.     }
  110.     public Ce_GlassProgreSsBar()
  111.         : base()
  112.     {
  113.         DoubleBuffered = true;
  114.         SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
  115.  
  116.         if (!InDesignMode())
  117.         {
  118.             GlowAnimation.Interval = 15;
  119.             if (Value < 100)
  120.                 GlowAnimation.Start();
  121.  
  122.             GlowAnimation.Tick += GlowAnimation_Tick;
  123.         }
  124.     }
  125.  
  126.     private int _mGlowPosition = -100;
  127.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  128.     {
  129.         Bitmap B = new Bitmap(Width, Height);
  130.         Graphics G = Graphics.FromImage(B);
  131.         G.SmoothingMode = SmoothingMode.HighQuality;
  132.  
  133.         G.Clear(Color.FromArgb(43, 53, 63));
  134.         //   -------------------Draw Background for the MBProgressBar--------------------
  135.  
  136.         LinearGradientBrush s2 = new LinearGradientBrush(new Rectangle(0, 2, Width - 3, 50), Color.FromArgb(35, 45, 55), Color.FromArgb(50, Color.White), 90);
  137.  
  138.         LinearGradientBrush s1 = new LinearGradientBrush(new Rectangle(0, 2, Width - 3, 50), Color.FromArgb(75, Color.White), Color.FromArgb(35, 45, 55), 90);
  139.  
  140.         Rectangle BackRectangle = this.ClientRectangle;
  141.         BackRectangle.Width = BackRectangle.Width - 1;
  142.         BackRectangle.Height = BackRectangle.Height - 1;
  143.         GraphicsPath GrafP = RoundRect(BackRectangle, 2, 2, 2, 2);
  144.         G.FillPath(s1, GrafP);
  145.  
  146.  
  147.         //--------------------Draw Background Shadows for MBProgrssBar------------------
  148.         Rectangle BGSH = new Rectangle(2, 2, 10, this.Height - 5);
  149.         LinearGradientBrush LGBS = new LinearGradientBrush(BGSH, Color.FromArgb(70, 80, 90), Color.FromArgb(95, 105, 115), LinearGradientMode.Horizontal);
  150.         G.FillRectangle(LGBS, BGSH);
  151.         Rectangle BGSRectangle = new Rectangle(this.Width - 12, 2, 10, this.Height - 5);
  152.         LinearGradientBrush LG = new LinearGradientBrush(BGSRectangle, Color.FromArgb(80, 90, 100), Color.FromArgb(75, 85, 95), LinearGradientMode.Horizontal);
  153.         G.FillRectangle(LG, BGSRectangle);
  154.  
  155.  
  156.         //----------------------Draw MBProgressBar-------------------- 
  157.         Rectangle ProgressRect = new Rectangle(1, 2, this.Width - 3, this.Height - 3);
  158.         ProgressRect.Width = Convert.ToInt32((Value * 1f / (100) * this.Width));
  159.         G.FillRectangle(s2, ProgressRect);
  160.  
  161.  
  162.         //----------------------Draw Shadows for MBProgressBar------------------
  163.         Rectangle SHRect = new Rectangle(1, 2, 15, this.Height - 3);
  164.         LinearGradientBrush LGSHP = new LinearGradientBrush(SHRect, Color.Black, Color.Black, LinearGradientMode.Horizontal);
  165.  
  166.         ColorBlend BColor = new ColorBlend(3);
  167.         BColor.Colors = new Color[] {
  168.             Color.Gray,
  169.             Color.FromArgb(40, 0, 0, 0),
  170.             Color.Transparent
  171.         };
  172.         BColor.Positions = new float[] {
  173.             0f,
  174.             0.2f,
  175.             1f
  176.         };
  177.         LGSHP.InterpolationColors = BColor;
  178.  
  179.         SHRect.X = SHRect.X - 1;
  180.         G.FillRectangle(LGSHP, SHRect);
  181.  
  182.         Rectangle Rect1 = new Rectangle(this.Width - 3, 2, 15, this.Height - 3);
  183.         Rect1.X = Convert.ToInt32((Value * 1f / (100) * this.Width) - 14);
  184.         LinearGradientBrush LGSH1 = new LinearGradientBrush(Rect1, Color.Black, Color.Black, LinearGradientMode.Horizontal);
  185.  
  186.         ColorBlend BColor1 = new ColorBlend(3);
  187.         BColor1.Colors = new Color[] {
  188.             Color.Transparent,
  189.             Color.FromArgb(70, 0, 0, 0),
  190.             Color.Transparent
  191.         };
  192.         BColor1.Positions = new float[] {
  193.             0f,
  194.             0.8f,
  195.             1f
  196.         };
  197.         LGSH1.InterpolationColors = BColor1;
  198.  
  199.         G.FillRectangle(LGSH1, Rect1);
  200.  
  201.  
  202.         //-------------------------Draw Highlight for MBProgressBar-----------------
  203.         Rectangle HLRect = new Rectangle(1, 1, this.Width - 1, 6);
  204.         GraphicsPath HLGPa = RoundRect(HLRect, 2, 2, 0, 0);
  205.         //G.SetClip(HLGPa)
  206.         LinearGradientBrush HLGBS = new LinearGradientBrush(HLRect, Color.FromArgb(190, 190, 190), Color.FromArgb(150, 150, 150), LinearGradientMode.Vertical);
  207.         G.FillPath(HLGBS, HLGPa);
  208.         G.ResetClip();
  209.         Rectangle HLrect2 = new Rectangle(1, this.Height - 8, this.Width - 1, 6);
  210.         GraphicsPath bp1 = RoundRect(HLrect2, 0, 0, 2, 2);
  211.         // G.SetClip(bp1)
  212.         LinearGradientBrush bg1 = new LinearGradientBrush(HLrect2, Color.Transparent, Color.FromArgb(150, this.HighlightColor), LinearGradientMode.Vertical);
  213.         G.FillPath(bg1, bp1);
  214.         G.ResetClip();
  215.  
  216.  
  217.         //--------------------Draw Inner Sroke for MBProgressBar--------------
  218.         Rectangle Rect20 = this.ClientRectangle;
  219.         Rect20.X = Rect20.X + 1;
  220.         Rect20.Y = Rect20.Y + 1;
  221.         Rect20.Width -= 3;
  222.         Rect20.Height -= 3;
  223.         GraphicsPath Rect15 = RoundRect(Rect20, 2, 2, 2, 2);
  224.         G.DrawPath(new Pen(Color.FromArgb(55, 65, 75)), Rect15);
  225.  
  226.         //-----------------------Draw Outer Stroke on the Control----------------------------
  227.         Rectangle StrokeRect = this.ClientRectangle;
  228.         StrokeRect.Width = StrokeRect.Width - 1;
  229.         StrokeRect.Height = StrokeRect.Height - 1;
  230.         GraphicsPath GGH = RoundRect(StrokeRect, 2, 2, 2, 2);
  231.         G.DrawPath(new Pen(Color.FromArgb(122, 122, 122)), GGH);
  232.  
  233.         //------------------------Draw Glow for MBProgressBar-----------------------
  234.         Rectangle GlowRect = new Rectangle(_mGlowPosition, 6, 60, 60);
  235.         LinearGradientBrush GlowLGBS = new LinearGradientBrush(GlowRect, Color.FromArgb(127, 137, 147), Color.FromArgb(75, 85, 95), LinearGradientMode.Horizontal);
  236.         ColorBlend BColor3 = new ColorBlend(4);
  237.         BColor3.Colors = new Color[] {
  238.             Color.Transparent,
  239.             this.GlowColor,
  240.             this.GlowColor,
  241.             Color.Transparent
  242.         };
  243.         BColor3.Positions = new float[] {
  244.             0f,
  245.             0.5f,
  246.             0.6f,
  247.             1f
  248.         };
  249.         GlowLGBS.InterpolationColors = BColor3;
  250.         Rectangle clip = new Rectangle(1, 2, this.Width - 3, this.Height - 3);
  251.         clip.Width = Convert.ToInt32((Value * 1f / (100) * this.Width));
  252.         G.SetClip(clip);
  253.         G.FillRectangle(GlowLGBS, GlowRect);
  254.         G.ResetClip();
  255.  
  256.         e.Graphics.DrawImage((Bitmap)B.Clone(), 0, 0);
  257.         G.Dispose();
  258.         B.Dispose();
  259.     }
  260.  
  261.     private GraphicsPath RoundRect(RectangleF r, float r1, float r2, float r3, float r4)
  262.     {
  263.         float x = r.X;
  264.         float y = r.Y;
  265.         float w = r.Width;
  266.         float h = r.Height;
  267.         GraphicsPath rr5 = new GraphicsPath();
  268.         rr5.AddBezier(x, y + r1, x, y, x + r1, y, x + r1, y);
  269.         rr5.AddLine(x + r1, y, x + w - r2, y);
  270.         rr5.AddBezier(x + w - r2, y, x + w, y, x + w, y + r2, x + w, y + r2);
  271.         rr5.AddLine(x + w, y + r2, x + w, y + h - r3);
  272.         rr5.AddBezier(x + w, y + h - r3, x + w, y + h, x + w - r3, y + h, x + w - r3, y + h);
  273.         rr5.AddLine(x + w - r3, y + h, x + r4, y + h);
  274.         rr5.AddBezier(x + r4, y + h, x, y + h, x, y + h - r4, x, y + h - r4);
  275.         rr5.AddLine(x, y + h - r4, x, y + r1);
  276.         return rr5;
  277.     }
  278.     private void GlowAnimation_Tick(object sender, EventArgs e)
  279.     {
  280.         if (this.Animate)
  281.         {
  282.             _mGlowPosition += 4;
  283.             if (_mGlowPosition > this.Width)
  284.             {
  285.                 _mGlowPosition = -10;
  286.                 this.Invalidate();
  287.             }
  288.  
  289.  
  290.         }
  291.         else
  292.         {
  293.             GlowAnimation.Stop();
  294.  
  295.             _mGlowPosition = -50;
  296.         }
  297.     }
  298.  
  299. }
  300. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement