![]() |
|
N2Oxide ProgressBar [C# - GDI] - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework) +--- Thread: N2Oxide ProgressBar [C# - GDI] (/Thread-N2Oxide-ProgressBar-C-GDI) |
N2Oxide ProgressBar [C# - GDI] - ArkPhaze - 04-14-2013 Here's another GDI control I wrote in C#. Previews: ![]() EDIT: More previews: ![]() *Edited to curve the first part instead of making it square. ![]() 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
N2Oxide ProgressBar [C# - GDI] - ArkPhaze - 04-14-2013 Here's another GDI control I wrote in C#. Previews: ![]() EDIT: More previews: ![]() *Edited to curve the first part instead of making it square. ![]() 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
RE: N2Oxide ProgressBar [C# - GDI] - Linuxephus™ - 04-15-2013 Now that admittedly is a nice progress bar.:ok: RE: N2Oxide ProgressBar [C# - GDI] - Linuxephus™ - 04-15-2013 Now that admittedly is a nice progress bar.:ok: RE: N2Oxide ProgressBar [C# - GDI] - ArkPhaze - 04-15-2013 You can change the alpha settings as well to get the style that you want: ![]() As well as the color and a few other things: ![]() It was designed for darker backgrounds though. RE: N2Oxide ProgressBar [C# - GDI] - ArkPhaze - 04-15-2013 You can change the alpha settings as well to get the style that you want: ![]() As well as the color and a few other things: ![]() It was designed for darker backgrounds though. RE: N2Oxide ProgressBar [C# - GDI] - Linuxephus™ - 04-15-2013 (04-15-2013, 02:53 AM)ArkPhaze Wrote: You can change the alpha settings as well to get the style that you want: Then that would go well with the dark backgrounds I already prefer on my workstations. RE: N2Oxide ProgressBar [C# - GDI] - ArkPhaze - 04-15-2013 (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: @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... EDIT; Code Removed: Latest code here http://www.hackcommunity.com/Thread-N2Oxide-ProgressBar-C-GDI?pid=133097#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. RE: N2Oxide ProgressBar [C# - GDI] - ArkPhaze - 04-15-2013 (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: @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... EDIT; Code Removed: Latest code here http://www.hackcommunity.com/Thread-N2Oxide-ProgressBar-C-GDI?pid=133097#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. RE: N2Oxide ProgressBar [C# - GDI] - Linuxephus™ - 04-15-2013 (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: Yes, the space between the percentage counter and the progress bar could be narrowed another 5 clicks or so. Otherwise, even better. |