تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
هل اح يعرف كيف تصليح هذا الكود
#1
كود :
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing.Drawing2D;
/// <summary>
/// MBGlassStyleProgressBar Class © 2011 By Manoj Kishor Bhoir
/// </summary>
/// <remarks>Version 1.0.4348.33776</remarks>
[ToolboxItem(true), ToolboxBitmap(typeof(MBProgressBar), "MBGlassStyleProgressBar.MBProgressBar.bmp"), ToolboxItemFilter("System.Windows.Forms"), Description("Display the Bar that indicates the Progress of Operation.")]
[DefaultEvent("ValueChanged"), DefaultProperty("Value")]
public class MBProgressBar : System.Windows.Forms.UserControl
{

    #region "   Designer"

    /// <summary>
    /// Required by the Form Designer Variable
    /// </summary>
    private System.ComponentModel.IContainer Components;
    /// <summary>
    /// Create a Control and Initialize it.
    /// </summary>
    public MBProgressBar()
    {
        Load += MBProgressBar_Load;
        Paint += GlowAnimation_Paint;
        InitializeComponent();
        this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        this.SetStyle(ControlStyles.ResizeRedraw, true);
        this.SetStyle(ControlStyles.Selectable, true);
        this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        this.SetStyle(ControlStyles.UserPaint, true);
        this.BackColor = Color.Transparent;
        if (!InDesignMode()) {
            GlowAnimation.Interval = 15;
            if (Value < 100)
                GlowAnimation.Start();
            GlowAnimation.Tick += GlowAnimation_Tick;
        }
    }
    /// <summary>
    /// MBExplorer Overrides Dispose to CleanUp component list
    /// </summary>
    protected override void Dispose(bool disposing)
    {
        if (disposing) {
            if ((Components != null)) {
                Components.Dispose();
            }
        }
        base.Dispose(disposing);
    }

    #endregion

    #region "   Component Designer"
    /// <summary>
    /// Initialize the MBProgressBar Components
    /// </summary>
    public void InitializeComponent()
    {
        this.SuspendLayout();
        //
        //MBProgressBar
        //
        this.Name = "MBProgressBar";
        this.Size = new System.Drawing.Size(150, 20);
        this.ResumeLayout(false);

    }

    #endregion

    #region "   Properties"

    private Timer GlowAnimation = new Timer();

    private int _mGlowPosition = -325;
    #region "               Value"
    private Int32 _MValue = 0;
    /// <summary>
    /// Get or Set the Value displayed on the MBProgressBar
    /// </summary>
    [Category("MBProgressBar Value"), Description("The Value that is Displayed on the ProgressBar"), DefaultValue(0), Browsable(true)]
    public Int32 Value {
        get { return _MValue; }
        set {
            if (value > 100 | value < 0)
                return;
            _MValue = value;
            if (value < 100)
                GlowAnimation.Start();
            if (value == 100)
                GlowAnimation.Stop();
            this.Invalidate();
        }
    }
    #endregion

    #region "       Bar"

    private Color _mStartColor = Color.FromArgb(0, 192, 0);
    /// <summary>
    /// Get and Set the Display Color of the ProgressBar
    /// </summary>
    [Category("MBProgressBar Color"), Description("The Display Color of the MBProgressBar"), DefaultValue("0, 192, 0"), Browsable(true)]
    public Color Color {
        get { return _mStartColor; }
        set {
            _mStartColor = value;
            this.Invalidate();
        }
    }

    #endregion

    #region "   Heilight and Glow"

    private Color _mHighlightColor = Color.White;
    /// <summary>
    /// Get or Set the Highlight Color of the MBProgressBar
    /// </summary>
    [Category("MBProgressBar Color"), Description("The Highlight Color of the MBProgressBar"), DefaultValue("White"), Browsable(true)]
    public Color HighlightColor {
        get { return _mHighlightColor; }
        set {
            _mHighlightColor = value;
            this.Invalidate();
        }
    }

    private Color _mBackgroundColor = Color.FromArgb(201, 201, 201);
    /// <summary>
    /// Get or Set the Background Color of the MBProgressBar
    /// </summary>
    [Category("MBProgressBar Color"), Description("The Background Color of the MBProgressBar"), DefaultValue("201, 201, 201"), Browsable(true)]
    public Color BackgroundColor {
        get { return _mBackgroundColor; }
        set {
            _mBackgroundColor = value;
            this.Invalidate();
        }
    }

    private bool _mAnimate = true;
    /// <summary>
    /// Get or Set the Animation of the MBProgressBar
    /// </summary>
    public bool Animate {
        get { return _mAnimate; }
        set {
            _mAnimate = value;
            if (value == true) {
                GlowAnimation.Start();
            } else {
                GlowAnimation.Stop();
            }
            this.Invalidate();
        }
    }

    private Color _mGlowColor = Color.FromArgb(150, 255, 255, 255);
    /// <summary>
    /// Get or Set the Glow Color of the MBProgressBar
    /// </summary>
    [Category("MBProgressBar Color"), Description("The Glow Color of the MBProgressBar"), DefaultValue("150, 255, 255, 255"), Browsable(true)]
    public Color GlowColor {
        get { return _mGlowColor; }
        set {
            _mGlowColor = value;
            this.Invalidate();
        }
    }
    #endregion

    #endregion

    #region "   Drawings"
    /// <summary>
    /// Draw Background for the MBProgressBar
    /// </summary>
    /// <param name="g">Graphics Object</param>
    private void DrawBackground(Graphics g)
    {
        Rectangle r = this.ClientRectangle;
        r.Width = r.Width - 1;
        r.Height = r.Height - 1;
        GraphicsPath rr = RoundRect(r, 2, 2, 2, 2);
        g.FillPath(new SolidBrush(this.BackgroundColor), rr);
    }
    /// <summary>
    /// Draw Background Shadows for MBProgrssBar
    /// </summary>
    /// <param name="g">Graphics Object</param>
    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 = lr.X - 1;
        g.FillRectangle(lg, lr);
        Rectangle rr = new Rectangle(this.Width - 12, 2, 10, this.Height - 5);
        LinearGradientBrush rg = new LinearGradientBrush(lr, Color.Transparent, Color.FromArgb(20, 0, 0, 0), LinearGradientMode.Horizontal);
        lr.X = lr.X - 1;
        g.FillRectangle(rg, rr);
    }
    /// <summary>
    /// Draw MBProgressBar
    /// </summary>
    /// <param name="g">Graphics Object</param>
    private void DrawBar(Graphics g)
    {
        Rectangle r = new Rectangle(1, 2, this.Width - 3, this.Height - 3);
        r.Width = Convert.ToInt32((Value * 1f / (100) * this.Width));
        g.FillRectangle(new SolidBrush(Color()), r);
    }
    /// <summary>
    /// Draw Shadows for MBProgressBar
    /// </summary>
    /// <param name="g">Graphics Object</param>
    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[] {
            0f,
            0.2f,
            1f
        };
        lg.InterpolationColors = lc;

        lr.X = lr.X - 1;
        g.FillRectangle(lg, lr);

        Rectangle rr = new Rectangle(this.Width - 3, 2, 15, this.Height - 3);
        rr.X = Convert.ToInt32((Value * 1f / (100) * 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[] {
            0f,
            0.8f,
            1f
        };
        rg.InterpolationColors = rc;

        g.FillRectangle(rg, rr);
    }
    /// <summary>
    /// Draw Highlight for MBProgressBar
    /// </summary>
    /// <param name="g">Graphics Object</param>
    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();
    }
    /// <summary>
    /// Draw Inner Sroke for MBProgressBar
    /// </summary>
    /// <param name="g">Graphics Object</param>
    private void DrawInnerStroke(Graphics g)
    {
        Rectangle r = this.ClientRectangle;
        r.X = r.X + 1;
        r.Y = r.Y + 1;
        r.Width -= 3;
        r.Height -= 3;
        GraphicsPath rr = RoundRect(r, 2, 2, 2, 2);
        g.DrawPath(new Pen(Color.FromArgb(100, Color.White)), rr);
    }
    /// <summary>
    /// Draw Glow for MBProgressBar
    /// </summary>
    /// <param name="g">Graphics Object</param>
    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[] {
            0f,
            0.5f,
            0.6f,
            1f
        };
        lgb.InterpolationColors = cb;
        Rectangle clip = new Rectangle(1, 2, this.Width - 3, this.Height - 3);
        clip.Width = Convert.ToInt32((Value * 1f / (100) * this.Width));
        g.SetClip(clip);
        g.FillRectangle(lgb, r);
        g.ResetClip();
    }
    /// <summary>
    /// Draw Outer Stroke on the Control
    /// </summary>
    /// <param name="g">Object As Graphics</param>
    private void DrawOuterStroke(Graphics g)
    {
        Rectangle r = this.ClientRectangle;
        r.Width = r.Width - 1;
        r.Height = r.Height - 1;
        GraphicsPath rr = RoundRect(r, 2, 2, 2, 2);
        g.DrawPath(new Pen(Color.FromArgb(178, 178, 178)), rr);
    }

    #endregion

    #region "   Functions"

    private bool InDesignMode()
    {
        return (LicenseManager.UsageMode == LicenseUsageMode.Designtime);
    }
    /// <summary>
    /// Return Rounded Rectangel
    /// </summary>
    /// <returns>Rounded Rectangle</returns>
    private GraphicsPath RoundRect(RectangleF r, float r1, float r2, float r3, float r4)
    {
        float x = r.X;
        float y = r.Y;
        float w = r.Width;
        float h = r.Height;
        GraphicsPath rr = new GraphicsPath();
        rr.AddBezier(x, y + r1, x, y, x + r1, y, x + r1, y);
        rr.AddLine(x + r1, y, x + w - r2, y);
        rr.AddBezier(x + w - r2, y, x + w, y, x + w, y + r2, x + w, y + r2);
        rr.AddLine(x + w, y + r2, x + w, y + h - r3);
        rr.AddBezier(x + w, y + h - r3, x + w, y + h, x + w - r3, y + h, x + w - r3, y + h);
        rr.AddLine(x + w - r3, y + h, x + r4, y + h);
        rr.AddBezier(x + r4, y + h, x, y + h, x, y + h - r4, x, y + h - r4);
        rr.AddLine(x, y + h - r4, x, y + r1);
        return rr;
    }

    #endregion

    #region "   Events"
    /// <summary>
    /// When the Value Property Changed
    /// </summary>
    public delegate void ValueChangedHandler(object sender, EventArgs e);
    /// <summary>
    /// When the Value Property Changed
    /// </summary>
    public event ValueChangedHandler ValueChanged;

    /// <summary>
    /// When the MinValue Property Changed
    /// </summary>
    public delegate void MinChangedHandler(object sender, EventArgs e);
    /// <summary>
    /// When the MinValue Property Changed
    /// </summary>
    public event MinChangedHandler MinChanged;

    /// <summary>
    /// When MaxValue Property Changed
    /// </summary>
    public delegate void MaxChangedHandler(object sender, EventArgs e);
    /// <summary>
    /// When MaxValue Property Changed
    /// </summary>
    public event MaxChangedHandler MaxChanged;
    #endregion

    #region "   Others"
    /// <summary>
    /// Handles GlowAnimation of MBProgressBar Pain Event
    /// </summary>
    private void GlowAnimation_Paint(object sender, System.Windows.Forms.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);
    }
    /// <summary>
    /// Timer Tick Event of GlowAnimation Timer Which Handls GlowAnimation of MBProgressBar
    /// </summary>
    private void GlowAnimation_Tick(object sender, EventArgs e)
    {
        if (this.Animate) {
            _mGlowPosition += 4;
            if (_mGlowPosition > this.Width) {
                _mGlowPosition = -300;
                this.Invalidate();
            }
        } else {
            GlowAnimation.Stop();
            _mGlowPosition = -320;
        }
    }

    #endregion


    private void MBProgressBar_Load(System.Object sender, System.EventArgs e)
    {
    }
}
الخطئ فى هذا السطر
إقتباس : g.FillRectangle(new SolidBrush(Color()), r);
الرد }}}
تم الشكر بواسطة:



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم