Progresbar like Vist




private void ProgressBar_Paint(object sender, PaintEventArgs e)
{
 e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
 e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
 DrawBackground(e.Graphics);
 DrawBackgroundShadows(e.Graphics);
 DrawBar(e.Graphics);
 DrawBarShadows(e.Graphics);
 DrawHighlight(e.Graphics);
 DrawInnerStroke(e.Graphics);
 DrawGlow(e.Graphics);

 DrawOuterStroke(e.Graphics);
}
//----------------------------------------------------------------------
private void DrawBackground(Graphics g)
{
 Rectangle r = this.ClientRectangle; r.Width--; r.Height--;
 GraphicsPath rr = RoundRect(r, 2, 2, 2, 2);
 g.FillPath(new SolidBrush(this.BackgroundColor), rr);
}
//----------------------------------------------------------------------
private void DrawBackgroundShadows(Graphics g)
{
 Rectangle lr = new Rectangle(2, 2, 10, this.Height - 5);
 LinearGradientBrush lg = new LinearGradientBrush
                          (lr, Color.FromArgb(30, 0, 0, 0),
                          Color.Transparent,
                          LinearGradientMode.Horizontal);
 lr.X--;
 g.FillRectangle(lg, lr);
 Rectangle rr = new Rectangle(this.Width - 12, 2, 10, this.Height - 5);
 LinearGradientBrush rg = new LinearGradientBrush(rr, Color.Transparent,
                          Color.FromArgb(20, 0, 0, 0),
                          LinearGradientMode.Horizontal);
 g.FillRectangle(rg, rr);
}
//----------------------------------------------------------------------
private void DrawBar(Graphics g)
{
 Rectangle r = new Rectangle(1, 2, this.Width - 3, this.Height - 3);
 r.Width = (int)(Value * 1.0F / (MaxValue - MinValue) * this.Width);
 g.FillRectangle(new SolidBrush(GetIntermediateColor()), r);
}
//----------------------------------------------------------------------
private void DrawBarShadows(Graphics g)
{
 Rectangle lr = new Rectangle(1, 2, 15, this.Height - 3);
 LinearGradientBrush lg = new LinearGradientBrush
                     (lr, Color.White, Color.White,
                          LinearGradientMode.Horizontal);
 ColorBlend lc = new ColorBlend(3);
 lc.Colors = new Color[]
 {Color.Transparent, Color.FromArgb(40, 0, 0, 0), Color.Transparent};
 lc.Positions = new float[] {0.0F, 0.2F, 1.0F};
 lg.InterpolationColors = lc;
 lr.X--;
 g.FillRectangle(lg, lr);
 Rectangle rr = new Rectangle(this.Width - 3, 2, 15, this.Height - 3);
 rr.X = (int)(Value * 1.0F / (MaxValue - MinValue) * this.Width) - 14;
 LinearGradientBrush rg =
     new LinearGradientBrush(rr, Color.Black,Color.Black,
                          LinearGradientMode.Horizontal);
 ColorBlend rc = new ColorBlend(3);
 rc.Colors = new Color[]
 {Color.Transparent, Color.FromArgb(40, 0, 0, 0), Color.Transparent};
 rc.Positions = new float[] {0.0F, 0.8F, 1.0F};
 rg.InterpolationColors = rc;
 g.FillRectangle(rg, rr);
}
//----------------------------------------------------------------------
private void DrawHighlight(Graphics g)
{
 Rectangle tr = new Rectangle(1, 1, this.Width - 1, 6);
 GraphicsPath tp = RoundRect(tr, 2, 2, 0, 0);
 g.SetClip(tp);
 LinearGradientBrush tg = new LinearGradientBrush(tr, Color.White,
                          Color.FromArgb(128, Color.White),
                          LinearGradientMode.Vertical);
 g.FillPath(tg, tp);
 g.ResetClip();
 Rectangle br = new Rectangle(1, this.Height - 8, this.Width - 1, 6);
 GraphicsPath bp = RoundRect(br, 0, 0, 2, 2);
 g.SetClip(bp);
 LinearGradientBrush bg = new LinearGradientBrush(br, Color.Transparent,
                          Color.FromArgb(100, this.HighlightColor),
                          LinearGradientMode.Vertical);
 g.FillPath(bg, bp);
 g.ResetClip();
}
//----------------------------------------------------------------------
private void DrawInnerStroke(Graphics g)
{
 Rectangle r = this.ClientRectangle;
 r.X++; r.Y++; r.Width-=3; r.Height-=3;
 GraphicsPath rr = RoundRect(r, 2, 2, 2, 2);
 g.DrawPath(new Pen(Color.FromArgb(100, Color.White)), rr);
}
//----------------------------------------------------------------------
private void DrawGlow(Graphics g)
{
 Rectangle r = new Rectangle(mGlowPosition, 0, 60, this.Height);
 LinearGradientBrush lgb = new LinearGradientBrush
                       (r, Color.White, Color.White,
                           LinearGradientMode.Horizontal);
 ColorBlend cb = new ColorBlend(4);
 cb.Colors = new Color[]
 {Color.Transparent, this.GlowColor, this.GlowColor, Color.Transparent};
 cb.Positions = new float[] {0.0F, 0.5F, 0.6F, 1.0F};
 lgb.InterpolationColors = cb;
 Rectangle clip = new Rectangle(1, 2, this.Width - 3, this.Height - 3);
 clip.Width = (int)(Value * 1.0F / (MaxValue - MinValue) * this.Width);
 g.SetClip(clip);
 g.FillRectangle(lgb,r);
 g.ResetClip();
}
//----------------------------------------------------------------------
private void DrawOuterStroke(Graphics g)
{
 Rectangle r = this.ClientRectangle; r.Width--; r.Height--;
 GraphicsPath rr = RoundRect(r, 2, 2, 2, 2);
 g.DrawPath(new Pen(Color.FromArgb(178, 178, 178)), rr);
}

No comments: