Advertisement
Alex-Trader

ColorProgressBar

Jul 29th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4.  
  5.  
  6. public class ColorProgressBar : ProgressBar
  7. {
  8.         public ColorProgressBar()
  9.         {
  10.            
  11.            
  12.             base.SetStyle(ControlStyles.UserPaint |
  13.                 ControlStyles.AllPaintingInWmPaint |
  14.                 ControlStyles.OptimizedDoubleBuffer, true);
  15.         }
  16.  
  17.         protected override void OnPaint(PaintEventArgs e)
  18.         {
  19.             Brush backBrush = new SolidBrush(this.BackColor);
  20.             Brush foreBrush = new SolidBrush(this.ForeColor);
  21.  
  22.            
  23.             e.Graphics.FillRectangle(backBrush, this.ClientRectangle);
  24.  
  25.            
  26.             int chunksWidth = (int)(
  27.                 (double)this.ClientSize.Width *
  28.                 (double)(this.Value - this.Minimum) /
  29.                 (double)(this.Maximum - this.Minimum));
  30.             Rectangle chunksRect = new Rectangle(0, 0,
  31.                 chunksWidth, this.ClientSize.Height);
  32.            
  33.             e.Graphics.FillRectangle(foreBrush, chunksRect);
  34.  
  35.             backBrush.Dispose();
  36.             foreBrush.Dispose();
  37.         }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement