RE: N2Oxide ProgressBar [C# - GDI] 04-15-2013, 04:27 AM
#11
(04-15-2013, 04:21 AM)ArkPhaze Wrote: @Linuxephus - I've made another update to this progress bar look/style. It now is modified to show a visual display of the percentage too. This is the good sh*t:
EDIT; Looks as though that separator is a bit low on the Y. Perhaps I'll bring that up a bit...
Code:using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace N2Oxide { class N2OxideProgBar : ProgressBar { private const int MaxHeight = 18; private const int CurvePadding = 4; private const int IndicatorPadding = 5; private const int DispOffset = 40; private readonly Color _bgCrossColor = Color.FromArgb(20, 20, 20); private readonly Color _bgBottomShineColor = Color.FromArgb(45, 255, 255, 255); private readonly Color _indicatorColor = Color.FromArgb(255, 45, 255, 150); private const int IndicatorAlpha = 215; public N2OxideProgBar() { DoubleBuffered = true; Size = new Size(120, MaxHeight); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.ResizeRedraw, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); BackColor = Color.Transparent; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; using (GraphicsPath gp = new GraphicsPath()) { // Draw Background Bottom Shine gp.AddLine(new Point(CurvePadding, 1), new Point(Width - CurvePadding, 1)); gp.AddCurve(new[] { new Point(Width - CurvePadding, 1), new Point(Width, Height / 2 - 1), new Point(Width - CurvePadding, Height) }, 1.2f); gp.AddLine(new Point(Width - CurvePadding, Height), new Point(CurvePadding, Height)); gp.CloseFigure(); e.Graphics.SetClip(gp); using (SolidBrush sb = new SolidBrush(_bgBottomShineColor)) e.Graphics.FillPath(sb, gp); gp.Reset(); // Draw Background Dark Gradient gp.AddLine(new Point(CurvePadding, 0), new Point(Width - CurvePadding, 0)); gp.AddCurve(new[] { new Point(Width - CurvePadding, 0), new Point(Width, Height / 2 - 1), new Point(Width - CurvePadding, Height - 2) }, 1.2f); gp.AddLine(new Point(Width - CurvePadding, Height - 2), new Point(CurvePadding, Height - 2)); gp.CloseFigure(); using (HatchBrush hg = new HatchBrush(HatchStyle.DarkDownwardDiagonal, _bgCrossColor)) e.Graphics.FillPath(hg, gp); gp.Reset(); // Draw Front Progress Indicator double progressPercent = (double)Value / Maximum; using (LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0, IndicatorPadding / 2 + 1, Width, Height), Color.FromArgb(IndicatorAlpha, _indicatorColor), Color.FromArgb(200, 0, 0, 0), 90f)) { if (progressPercent > 0) { gp.AddLine(new Point(DispOffset + 2, IndicatorPadding), new Point((int)((Width - DispOffset) * progressPercent) - IndicatorPadding + DispOffset, IndicatorPadding)); gp.AddCurve( new[] { new Point((int)((Width - DispOffset) * progressPercent) - IndicatorPadding - CurvePadding + DispOffset, IndicatorPadding), new Point((int)((Width - DispOffset) * progressPercent) - IndicatorPadding + DispOffset, Height / 2), new Point((int)((Width - DispOffset) * progressPercent) - IndicatorPadding - CurvePadding + DispOffset, Height - IndicatorPadding) }, 1.2f); gp.AddLine(new Point((int)((Width - DispOffset) * progressPercent) - IndicatorPadding + DispOffset, Height - IndicatorPadding), new Point(DispOffset + 2, Height - IndicatorPadding)); gp.CloseFigure(); e.Graphics.FillPath(lgb, gp); } gp.Reset(); gp.AddRectangle(new Rectangle(DispOffset, 0, 2, Height - 2)); gp.CloseFigure(); e.Graphics.FillPath(lgb, gp); } e.Graphics.ResetClip(); // Draw Percent Display string percent = Value + "%"; SizeF fontSize = e.Graphics.MeasureString(percent, Font); e.Graphics.DrawString(percent, Font, Brushes.LightGray, 5, Height / 2 - fontSize.Height / 2); } } protected override void OnResize(EventArgs e) { base.OnResize(e); Size = new Size(Size.Width, MaxHeight); } } }
Cleaned up the code some as well...
Yes, the space between the percentage counter and the progress bar could be narrowed another 5 clicks or so.
Otherwise, even better.

![[Image: QXm7KVw.png]](http://i.imgur.com/QXm7KVw.png)
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)
![[Image: KxNSj27.png]](http://i.imgur.com/KxNSj27.png)

![[Image: qL2bH67.png]](http://i.imgur.com/qL2bH67.png)
![[Image: OHfDpcG.png]](http://i.imgur.com/OHfDpcG.png)
![[Image: EvIzsof.png]](http://i.imgur.com/EvIzsof.png)
miling:![[Image: OilyCostlyEwe.gif]](http://fat.gfycat.com/OilyCostlyEwe.gif)
![[Image: qOdyrpP.png]](http://i.imgur.com/qOdyrpP.png)

