ColoredProgress.cs 921 B

12345678910111213141516171819202122232425262728
  1. using System.Drawing;
  2. using System.Drawing.Drawing2D;
  3. using System.Windows.Forms;
  4. namespace Optimizer
  5. {
  6. internal class ColoredProgress : ProgressBar
  7. {
  8. public ColoredProgress()
  9. {
  10. this.SetStyle(ControlStyles.UserPaint, true);
  11. }
  12. protected override void OnPaint(PaintEventArgs e)
  13. {
  14. LinearGradientBrush brush = null;
  15. Rectangle rec = new Rectangle(0, 0, this.Width, this.Height);
  16. if (ProgressBarRenderer.IsSupported)
  17. ProgressBarRenderer.DrawHorizontalBar(e.Graphics, rec);
  18. rec.Width = (int)(rec.Width * ((double)base.Value / Maximum)) - 4;
  19. rec.Height -= 4;
  20. brush = new LinearGradientBrush(rec, Options.ForegroundAccentColor, Options.ForegroundColor, LinearGradientMode.Vertical);
  21. e.Graphics.FillRectangle(brush, 2, 2, rec.Width, rec.Height);
  22. }
  23. }
  24. }