Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- namespace SplittyDev.Progress
- {
- public class ProgressLabel : Control
- {
- internal int value;
- public int Value { get { return value; } set { this.value = value; this.Refresh (); } }
- internal Color foreColor;
- public Color ForegroundColor { get { return foreColor; } set { foreColor = value; this.Refresh (); } }
- internal Color fillColor;
- public Color FillColor { get { return fillColor; } set { fillColor = value; this.Refresh (); } }
- internal bool optimize;
- public bool Optimize { get { return optimize; } set { optimize = value; this.Refresh (); } }
- internal bool displayPercentage;
- public bool DisplayPercentage { get { return displayPercentage; } set { displayPercentage = value; this.Refresh (); } }
- public ProgressLabel ()
- {
- SetStyle (ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw |
- ControlStyles.UserPaint, true);
- SetStyle (ControlStyles.FixedWidth | ControlStyles.FixedHeight, true);
- UpdateStyles ();
- this.value = 0;
- this.foreColor = Color.Gray;
- this.fillColor = Color.DeepSkyBlue;
- this.Font = new Font (SystemFonts.DefaultFont.FontFamily, 74f, FontStyle.Regular, GraphicsUnit.Pixel);
- this.displayPercentage = true;
- this.optimize = true;
- }
- protected override void OnInvalidated (InvalidateEventArgs e)
- {
- Size size = TextRenderer.MeasureText (this.value.ToString () + ((displayPercentage) ? "%" : ""), this.Font);
- this.Size = size;
- base.OnInvalidated (e);
- }
- protected override void OnPaint (PaintEventArgs e)
- {
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
- e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
- Rectangle rect = e.ClipRectangle;
- if (Optimize) rect.Inflate (- (this.Size.Width / 7), - (this.Size.Height / 7));
- using (LinearGradientBrush overlay = new LinearGradientBrush (rect, foreColor, fillColor, LinearGradientMode.Vertical))
- {
- float val = 1.0f - (float)(((float)value) / 100.0f);
- Blend blend = new Blend ();
- blend.Factors = new float[] { 0f, 0f, 0.5f, 1f, 1f };
- blend.Positions = new float[] { 0f, (val >= 0.001f) ? val - 0.001f : 0.001f, val, (val <= 0.999f) ? val + 0.001f : 0.999f, 1.0f };
- overlay.Blend = blend;
- e.Graphics.DrawString (this.value.ToString () + ((displayPercentage) ? "%" : ""), this.Font, overlay, new Point (0, 0));
- }
- base.OnPaint (e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement