Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

ProgressBar control with text / percentage!

(Oct 29, 2014 01:12 PM)WZDY Wrote:  He could just do it in the Properties of the textbox?

😊 what textbox

want short code

Code
class TextProgressBar : ProgressBar
{

    public TextProgressBar()
    {
        SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        Graphics G = e.Graphics;
        ProgressBarRenderer.DrawHorizontalBar(G, ClientRectangle);
        if (Value > 0) {
            ProgressBarRenderer.DrawHorizontalChunks(G, new Rectangle(ClientRectangle.X, ClientRectangle.Y, Convert.ToInt32(Math.Round((Convert.ToSingle(Value) / Maximum) * ClientRectangle.Width)), ClientRectangle.Height));
      }
        SizeF TextSize = G.MeasureString(Value, new Font("Segoe UI", 10));
        G.DrawString(Value, new Font("Segoe UI", 10), Brushes.Black, new Point((Width / 2) - (TextSize.Width / 2), (Height / 2) - (TextSize.Height / 2)));
    }
}


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by elmagekOct 24, 2021 02:50 PM 7 288 Oct 24, 2021 02:50 PM
Last Post: #Kat
[.NET] by Dir50Jun 5, 2018 08:56 AM 9 309 Jun 5, 2018 08:56 AM
Last Post: 0xDEAD10CC
[.NET] by DeStilleGastJul 4, 2016 03:09 AM 3 424 Jul 4, 2016 03:09 AM
Last Post: DeStilleGast