Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PercentProgressBar : ProgressBar
- {
- public PercentProgressBar()
- {
- base.SetStyle(ControlStyles.UserPaint |
- ControlStyles.AllPaintingInWmPaint |
- ControlStyles.OptimizedDoubleBuffer, true);
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- ProgressBarRenderer.DrawHorizontalBar(e.Graphics, this.ClientRectangle);
- double percent = (double)(this.Value - this.Minimum)
- / (double)(this.Maximum - this.Minimum);
- int chunksWidth = (int)((double)(this.ClientSize.Width - 2) * percent);
- Rectangle chunksRect = new Rectangle(1, 1,
- chunksWidth, this.ClientSize.Height - 2);
- ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, chunksRect);
- string displayText = string.Format("{0}%", (int)(percent * 100.0));
- TextFormatFlags tff = TextFormatFlags.HorizontalCenter |
- TextFormatFlags.VerticalCenter |
- TextFormatFlags.SingleLine;
- TextRenderer.DrawText(e.Graphics, displayText, this.Font,
- this.ClientRectangle, SystemColors.ControlText, tff);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement