Login Register


N2Oxide ProgressBar [C# - GDI] filter_list
Author
Message
N2Oxide ProgressBar [C# - GDI] #1
Here's another GDI control I wrote in C#.

Previews:
[Image: KxNSj27.png]

EDIT: More previews:
[Image: qL2bH67.png]

*Edited to curve the first part instead of making it square.
[Image: K54a6ei.gif]

Code:
Code:
// N2Oxide Progress Bar // Author: ArkPhaze (c) 2013 // Site: HackCommunity.com 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 Color _bgCrossColor = Color.FromArgb(20, 20, 20); public Color BgCrossColor { get { return _bgCrossColor; } set { _bgCrossColor = value; } } private Color _bgBottomShineColor = Color.FromArgb(255, 255, 255); public Color BgBottomShineColor { get { return _bgBottomShineColor; } set { _bgBottomShineColor = value; } } private Color _indicatorColor = Color.FromArgb(255, 180, 80, 255); public Color IndicatorColor { get { return _indicatorColor; } set { _indicatorColor = value; } } private int _indicatorAlpha = 230; public int IndicatorAlpha { get { return _indicatorAlpha; } set { _indicatorAlpha = value; } } 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 sealed bool DoubleBuffered { get { return base.DoubleBuffered; } set { base.DoubleBuffered = value; } } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); BackColor = Color.Transparent; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; using (GraphicsPath gp = new GraphicsPath()) { // Draw Background Bottom Shine gp.AddCurve(new[] { new Point(CurvePadding, 0), new Point(0, Height / 2 - 1), new Point(CurvePadding, Height) }, 1.2f); 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) }, 1.0f); gp.AddLine(new Point(Width - CurvePadding, Height), new Point(CurvePadding, Height)); gp.CloseFigure(); using (SolidBrush sb = new SolidBrush(_bgBottomShineColor)) e.Graphics.FillPath(sb, gp); gp.Reset(); // Draw Background Dark Gradient int lineThickness = 2; gp.AddCurve(new[] { new Point(CurvePadding, 0), new Point(0, Height / 2 - 1), new Point(CurvePadding, Height - lineThickness) }, 1.2f); 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 - lineThickness) }, 1.0f); gp.AddLine(new Point(Width - CurvePadding, Height - lineThickness), new Point(CurvePadding, Height - lineThickness)); 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, 0, Width, Height), Color.FromArgb(IndicatorAlpha, _indicatorColor), Color.FromArgb(50, _indicatorColor), 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 - IndicatorPadding - 2) * progressPercent) - CurvePadding + DispOffset + 2, IndicatorPadding), new Point((int)((Width - DispOffset - IndicatorPadding - 2) * progressPercent) + DispOffset + 2, Height / 2), new Point((int)((Width - DispOffset - IndicatorPadding - 2) * progressPercent) - CurvePadding + DispOffset + 2, 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(); } // Draw Splitter e.Graphics.FillRectangle(lgb, new Rectangle(DispOffset, 1, 2, Height - 3)); } // 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); } } }

Enjoy Cool
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

N2Oxide ProgressBar [C# - GDI] #2
Here's another GDI control I wrote in C#.

Previews:
[Image: KxNSj27.png]

EDIT: More previews:
[Image: qL2bH67.png]

*Edited to curve the first part instead of making it square.
[Image: K54a6ei.gif]

Code:
Code:
// N2Oxide Progress Bar // Author: ArkPhaze (c) 2013 // Site: HackCommunity.com 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 Color _bgCrossColor = Color.FromArgb(20, 20, 20); public Color BgCrossColor { get { return _bgCrossColor; } set { _bgCrossColor = value; } } private Color _bgBottomShineColor = Color.FromArgb(255, 255, 255); public Color BgBottomShineColor { get { return _bgBottomShineColor; } set { _bgBottomShineColor = value; } } private Color _indicatorColor = Color.FromArgb(255, 180, 80, 255); public Color IndicatorColor { get { return _indicatorColor; } set { _indicatorColor = value; } } private int _indicatorAlpha = 230; public int IndicatorAlpha { get { return _indicatorAlpha; } set { _indicatorAlpha = value; } } 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 sealed bool DoubleBuffered { get { return base.DoubleBuffered; } set { base.DoubleBuffered = value; } } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); BackColor = Color.Transparent; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; using (GraphicsPath gp = new GraphicsPath()) { // Draw Background Bottom Shine gp.AddCurve(new[] { new Point(CurvePadding, 0), new Point(0, Height / 2 - 1), new Point(CurvePadding, Height) }, 1.2f); 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) }, 1.0f); gp.AddLine(new Point(Width - CurvePadding, Height), new Point(CurvePadding, Height)); gp.CloseFigure(); using (SolidBrush sb = new SolidBrush(_bgBottomShineColor)) e.Graphics.FillPath(sb, gp); gp.Reset(); // Draw Background Dark Gradient int lineThickness = 2; gp.AddCurve(new[] { new Point(CurvePadding, 0), new Point(0, Height / 2 - 1), new Point(CurvePadding, Height - lineThickness) }, 1.2f); 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 - lineThickness) }, 1.0f); gp.AddLine(new Point(Width - CurvePadding, Height - lineThickness), new Point(CurvePadding, Height - lineThickness)); 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, 0, Width, Height), Color.FromArgb(IndicatorAlpha, _indicatorColor), Color.FromArgb(50, _indicatorColor), 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 - IndicatorPadding - 2) * progressPercent) - CurvePadding + DispOffset + 2, IndicatorPadding), new Point((int)((Width - DispOffset - IndicatorPadding - 2) * progressPercent) + DispOffset + 2, Height / 2), new Point((int)((Width - DispOffset - IndicatorPadding - 2) * progressPercent) - CurvePadding + DispOffset + 2, 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(); } // Draw Splitter e.Graphics.FillRectangle(lgb, new Rectangle(DispOffset, 1, 2, Height - 3)); } // 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); } } }

Enjoy Cool
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: N2Oxide ProgressBar [C# - GDI] #3
Now that admittedly is a nice progress bar.:ok:

Reply

RE: N2Oxide ProgressBar [C# - GDI] #4
Now that admittedly is a nice progress bar.:ok:

Reply

RE: N2Oxide ProgressBar [C# - GDI] #5
You can change the alpha settings as well to get the style that you want:
[Image: OHfDpcG.png]

As well as the color and a few other things:
[Image: EvIzsof.png]

It was designed for darker backgrounds though.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: N2Oxide ProgressBar [C# - GDI] #6
You can change the alpha settings as well to get the style that you want:
[Image: OHfDpcG.png]

As well as the color and a few other things:
[Image: EvIzsof.png]

It was designed for darker backgrounds though.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: N2Oxide ProgressBar [C# - GDI] #7
(04-15-2013, 02:53 AM)ArkPhaze Wrote: You can change the alpha settings as well to get the style that you want:
[Image: OHfDpcG.png]

As well as the color and a few other things:
[Image: EvIzsof.png]

It was designed for darker backgrounds though.

Then that would go well with the dark backgrounds I already prefer on my workstations.

Reply

RE: N2Oxide ProgressBar [C# - GDI] #8
(04-15-2013, 04:18 AM)Linuxephus Wrote:
(04-15-2013, 02:53 AM)ArkPhaze Wrote: You can change the alpha settings as well to get the style that you want:
[Image: OHfDpcG.png]

As well as the color and a few other things:
[Image: EvIzsof.png]

It was designed for darker backgrounds though.

Then that would go well with the dark backgrounds I already prefer on my workstations.

@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:

[Image: QXm7KVw.png]

EDIT; Looks as though that separator is a bit low on the Y. Perhaps I'll bring that up a bit...

EDIT; Code Removed: Latest code here http://www.hackcommunity.com/Thread-N2Ox...#pid133097

Cleaned up the code some as well... I'm working on cleanup right now.

@Psycho_Coder - I think you will appreciate this for a GDI example.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: N2Oxide ProgressBar [C# - GDI] #9
(04-15-2013, 04:18 AM)Linuxephus Wrote:
(04-15-2013, 02:53 AM)ArkPhaze Wrote: You can change the alpha settings as well to get the style that you want:
[Image: OHfDpcG.png]

As well as the color and a few other things:
[Image: EvIzsof.png]

It was designed for darker backgrounds though.

Then that would go well with the dark backgrounds I already prefer on my workstations.

@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:

[Image: QXm7KVw.png]

EDIT; Looks as though that separator is a bit low on the Y. Perhaps I'll bring that up a bit...

EDIT; Code Removed: Latest code here http://www.hackcommunity.com/Thread-N2Ox...#pid133097

Cleaned up the code some as well... I'm working on cleanup right now.

@Psycho_Coder - I think you will appreciate this for a GDI example.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: N2Oxide ProgressBar [C# - GDI] #10
(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:

[Image: QXm7KVw.png]

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.

Reply







Users browsing this thread: