Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GraphicsHelper
- {
- public GraphicsPath Createround(int X, int Y, int Width, int Height, int CornerRadius)
- {
- GraphicsPath gfxPath = new GraphicsPath();
- try
- {
- gfxPath.AddArc(X, Y, CornerRadius, CornerRadius, 180, 90);
- gfxPath.AddArc(X + Width - CornerRadius, Y, CornerRadius, CornerRadius, 270, 90);
- gfxPath.AddArc(X + Width - CornerRadius, Y + Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
- gfxPath.AddArc(X, Y + Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
- gfxPath.CloseAllFigures(); return gfxPath;
- }
- catch (Exception) { return null; }
- }
- }
- public class CustomProgressbar : Control
- {
- public int Value {get; set;}
- private int _Maximum = 100;
- public int Maximum
- {
- get { return _Maximum; }
- set { if (value > 0) { _Maximum = value; } else { throw new Exception("Fuck you. Maximum should be bigger than zero ;)"); }; }
- }
- public CustomProgressbar()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true);
- DoubleBuffered = true;
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- e.Graphics.Clear(BackColor);
- e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
- GraphicsPath barPath = new GraphicsHelper().Createround(0, 0, Width - 1, Height - 1, 3);
- e.Graphics.DrawPath(new Pen(Color.FromArgb(50, Color.Black)), barPath);
- e.Graphics.SetClip(barPath);
- LinearGradientBrush LGB = new LinearGradientBrush(new Rectangle(0, 2, Width - 1, Height - 3), Color.FromArgb(241,229,201), Color.FromArgb(237,218,202), 90F);
- e.Graphics.FillRectangle(LGB, LGB.Rectangle);
- e.Graphics.ResetClip();
- int DrawWidth = (int)(((double)Value / (double)_Maximum) * (double)(Width - 1));
- if (DrawWidth > 1)
- {
- GraphicsPath FilledPart = new GraphicsHelper().Createround(0, 0, DrawWidth, Height - 1, 3);
- LinearGradientBrush LGB2 = new LinearGradientBrush(new Rectangle(0, 1, DrawWidth , Height - 2), Color.FromArgb(232, 119, 9), Color.FromArgb(255, 171, 3), 90F);
- e.Graphics.FillRectangle(LGB2, LGB2.Rectangle);
- e.Graphics.DrawPath(new Pen(Color.FromArgb(146, 101, 11)), FilledPart);
- }
- base.OnPaint(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement