why getting parameter is not valid when dragging the custom progressbar to the form1 designer?

it was working fine first time when i dragged the custom progressbar to the form1 designer from the toolbox. but now each time i try to drag it i get the exception error message.

and i didn’t change anything.

link for the code where i took it from.

https://github.com/ukushu/TextProgressBar/blob/master/TextProgressBar.cs

here is an image screenshot showing the error message:

and the code

protected override void OnPaint(PaintEventArgs e)
{
    if (e.Graphics == null)
    {
        return;
    }

    Graphics g = e.Graphics;

    DrawProgressBar(g);

    DrawStringIfNeeded(g);
}

line 134 is:

DrawStringIfNeeded(g);

and

private void DrawStringIfNeeded(Graphics g)
{
    if (VisualMode != ProgressBarDisplayMode.NoText)
    {
        string text = _textToDraw;

        if (!string.IsNullOrEmpty(text))
        {
            SizeF len = g.MeasureString(text, TextFont);

            Point location = new Point((Width / 2) - (int)len.Width / 2, (Height / 2) - (int)len.Height / 2);

            g.DrawString(text, TextFont, _textColourBrush, location);
        }
    }
}

line 165 is:

g.DrawString(text, TextFont, _textColourBrush, location);

and the full code , it’s a bit long but might be needed:

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

public enum ProgressBarDisplayMode
{
    NoText,
    Percentage,
    CurrProgress,
    CustomText,
    TextAndPercentage,
    TextAndCurrProgress
}

public class CustomProgressBar : ProgressBar
{
    [Description("Font of the text on ProgressBar"), Category("Additional Options")]
    public Font TextFont { get; set; } = new Font(FontFamily.GenericSerif, 14, FontStyle.Bold | FontStyle.Italic);

    private SolidBrush _textColourBrush = (SolidBrush)Brushes.Black;
    [Category("Additional Options")]
    public Color TextColor
    {
        get
        {
            return _textColourBrush.Color;
        }
        set
        {
            _textColourBrush.Dispose();
            _textColourBrush = new SolidBrush(value);
        }
    }

    private SolidBrush _progressColourBrush = (SolidBrush)Brushes.LightGreen;
    [Category("Additional Options"), Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
    public Color ProgressColor
    {
        get
        {
            return _progressColourBrush.Color;
        }
        set
        {
            _progressColourBrush.Dispose();
            _progressColourBrush = new SolidBrush(value);
        }
    }

    private ProgressBarDisplayMode _visualMode = ProgressBarDisplayMode.Percentage;
    [Category("Additional Options"), Browsable(true)]
    public ProgressBarDisplayMode VisualMode
    {
        get
        {
            return _visualMode;
        }
        set
        {
            _visualMode = value;
            Invalidate(); // Redraw component after change value from VS Properties section
        }
    }

    private string _text = string.Empty;

    [Description("If it's empty, % will be shown"), Category("Additional Options"), Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
    public string CustomText
    {
        get
        {
            return _text;
        }
        set
        {
            _text = value;
            Invalidate(); // Redraw component after change value from VS Properties section
        }
    }

    private string _textToDraw
    {
        get
        {
            string text = CustomText;

            switch (VisualMode)
            {
                case ProgressBarDisplayMode.Percentage:
                    text = _percentageStr;
                    break;
                case ProgressBarDisplayMode.CurrProgress:
                    text = _currProgressStr;
                    break;
                case ProgressBarDisplayMode.TextAndCurrProgress:
                    text = $"{CustomText}: {_currProgressStr}";
                    break;
                case ProgressBarDisplayMode.TextAndPercentage:
                    text = $"{CustomText}: {_percentageStr}";
                    break;
            }

            return text;
        }
    }

    private string _percentageStr => $"{(int)((float)Value - Minimum) / ((float)Maximum - Minimum) * 100} %";

    private string _currProgressStr => $"{Value}/{Maximum}";

    public CustomProgressBar()
    {
        Value = Minimum;
        FixComponentBlinking();
    }

    private void FixComponentBlinking()
    {
        SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        if (e.Graphics == null)
        {
            return;
        }

        Graphics g = e.Graphics;

        DrawProgressBar(g);

        DrawStringIfNeeded(g);
    }

    private void DrawProgressBar(Graphics g)
    {
        Rectangle rect = ClientRectangle;

        ProgressBarRenderer.DrawHorizontalBar(g, rect);

        rect.Inflate(-3, -3);

        if (Value > 0)
        {
            Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);

            g.FillRectangle(_progressColourBrush, clip);
        }
    }

    private void DrawStringIfNeeded(Graphics g)
    {
        if (VisualMode != ProgressBarDisplayMode.NoText)
        {
            string text = _textToDraw;

            if (!string.IsNullOrEmpty(text))
            {
                SizeF len = g.MeasureString(text, TextFont);

                Point location = new Point((Width / 2) - (int)len.Width / 2, (Height / 2) - (int)len.Height / 2);

                g.DrawString(text, TextFont, _textColourBrush, location);
            }
        }
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            _textColourBrush?.Dispose();
            _progressColourBrush?.Dispose();
        }
        base.Dispose(disposing);
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật