Advertisement
Mavamaarten

YellowyProgressbar for Xoslize

Aug 12th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1.     class GraphicsHelper
  2.     {
  3.         public GraphicsPath Createround(int X, int Y, int Width, int Height, int CornerRadius)
  4.         {
  5.             GraphicsPath gfxPath = new GraphicsPath();
  6.             try
  7.             {
  8.                 gfxPath.AddArc(X, Y, CornerRadius, CornerRadius, 180, 90);
  9.                 gfxPath.AddArc(X + Width - CornerRadius, Y, CornerRadius, CornerRadius, 270, 90);
  10.                 gfxPath.AddArc(X + Width - CornerRadius, Y + Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
  11.                 gfxPath.AddArc(X, Y + Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
  12.                 gfxPath.CloseAllFigures(); return gfxPath;
  13.             }
  14.             catch (Exception) { return null; }
  15.         }
  16.     }
  17.  
  18.     public class CustomProgressbar : Control
  19.     {
  20.  
  21.         public int Value {get; set;}
  22.         private int _Maximum = 100;
  23.         public int Maximum
  24.         {
  25.             get { return _Maximum; }
  26.             set { if (value > 0) { _Maximum = value; } else { throw new Exception("Fuck you. Maximum should be bigger than zero ;)"); }; }
  27.         }
  28.  
  29.         public CustomProgressbar()
  30.         {
  31.             SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true);
  32.             DoubleBuffered = true;
  33.         }
  34.  
  35.         protected override void OnPaint(PaintEventArgs e)
  36.         {
  37.             e.Graphics.Clear(BackColor);
  38.             e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
  39.  
  40.  
  41.             GraphicsPath barPath = new GraphicsHelper().Createround(0, 0, Width - 1, Height - 1, 3);
  42.             e.Graphics.DrawPath(new Pen(Color.FromArgb(50, Color.Black)), barPath);
  43.             e.Graphics.SetClip(barPath);
  44.             LinearGradientBrush LGB = new LinearGradientBrush(new Rectangle(0, 2, Width - 1, Height - 3), Color.FromArgb(241,229,201), Color.FromArgb(237,218,202), 90F);
  45.             e.Graphics.FillRectangle(LGB, LGB.Rectangle);
  46.             e.Graphics.ResetClip();
  47.  
  48.             int DrawWidth = (int)(((double)Value / (double)_Maximum) * (double)(Width - 1));
  49.             if (DrawWidth > 1)
  50.             {
  51.                 GraphicsPath FilledPart = new GraphicsHelper().Createround(0, 0, DrawWidth, Height - 1, 3);
  52.                 LinearGradientBrush LGB2 = new LinearGradientBrush(new Rectangle(0, 1, DrawWidth , Height - 2), Color.FromArgb(232, 119, 9), Color.FromArgb(255, 171, 3), 90F);
  53.                 e.Graphics.FillRectangle(LGB2, LGB2.Rectangle);
  54.                 e.Graphics.DrawPath(new Pen(Color.FromArgb(146, 101, 11)), FilledPart);
  55.             }
  56.  
  57.             base.OnPaint(e);
  58.         }
  59.  
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement