You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 15, 2026. It is now read-only.
Thanks for your great work. It was just what I was looking for.
With a little help from ChatGPT I made a .NET9 version which still works very nicely.
I thought I share it here for others to use:
usingSystem.ComponentModel;
#pragma warning disable WFO1000namespaceWinFormApplication;publicclassTextProgressBar:ProgressBar{privateFont_textFont=new(FontFamily.GenericSerif,11,FontStyle.Bold|FontStyle.Italic);privateSolidBrush_textBrush=new(Color.Black);privateSolidBrush_progressBrush=new(Color.LightGreen);privateProgressBarDisplayMode_visualMode=ProgressBarDisplayMode.CurrProgress;privatestring_customText=string.Empty;[Category("Appearance")][Description("Font of the text displayed on the progress bar.")]publicFontTextFont{get=>_textFont;set{_textFont=value??thrownewArgumentNullException(nameof(TextFont));Invalidate();}}[Category("Appearance")][Description("Color of the text displayed on the progress bar.")]publicColorTextColor{get=>_textBrush.Color;set{if(_textBrush.Color!=value){_textBrush.Dispose();_textBrush=newSolidBrush(value);Invalidate();}}}[Category("Appearance")][Description("Color of the progress bar.")]publicColorProgressColor{get=>_progressBrush.Color;set{if(_progressBrush.Color!=value){_progressBrush.Dispose();_progressBrush=newSolidBrush(value);Invalidate();}}}[Category("Behavior")][Description("Defines the text display mode of the progress bar.")]publicProgressBarDisplayModeVisualMode{get=>_visualMode;set{if(_visualMode!=value){_visualMode=value;Invalidate();}}}[Category("Behavior")][Description("Custom text to display on the progress bar.")]publicstringCustomText{get=>_customText;set{_customText=value;Invalidate();}}publicTextProgressBar(){SetStyle(ControlStyles.UserPaint|ControlStyles.OptimizedDoubleBuffer|ControlStyles.AllPaintingInWmPaint,value:true);}protectedoverridevoidOnPaint(PaintEventArgse){varg=e.Graphics;DrawProgressBar(g);DrawText(g);}privatevoidDrawProgressBar(Graphicsg){varrect=ClientRectangle;ProgressBarRenderer.DrawHorizontalBar(g,rect);rect.Inflate(-3,-3);if(Value>0){varfillWidth=(int)((Value-Minimum)/(float)(Maximum-Minimum)*rect.Width);varfillRect=newRectangle(rect.X,rect.Y,fillWidth,rect.Height);g.FillRectangle(_progressBrush,fillRect);}}privatevoidDrawText(Graphicsg){if(VisualMode==ProgressBarDisplayMode.NoText)return;vartext=GetDisplayText();vartextSize=g.MeasureString(text,_textFont);varlocation=newPointF((Width-textSize.Width)/2,(Height-textSize.Height)/2);g.DrawString(text,_textFont,_textBrush,location);}privatestringGetDisplayText(){returnVisualModeswitch{ProgressBarDisplayMode.Percentage=>$"{(int)((Value-Minimum)/(float)(Maximum-Minimum)*100)}%",ProgressBarDisplayMode.CurrProgress=>$"{Value}/{Maximum}",ProgressBarDisplayMode.TextAndPercentage=>$"{_customText}: {(int)((Value-Minimum)/(float)(Maximum-Minimum)*100)}%",ProgressBarDisplayMode.TextAndCurrProgress=>$"{_customText}: {Value}/{Maximum}",
_ =>_customText,};}protectedoverridevoidDispose(booldisposing){if(disposing){_textBrush.Dispose();_progressBrush.Dispose();_textFont.Dispose();}base.Dispose(disposing);}publicenumProgressBarDisplayMode{NoText,Percentage,CurrProgress,CustomText,TextAndPercentage,TextAndCurrProgress,}}
Thanks for your great work. It was just what I was looking for.
With a little help from ChatGPT I made a .NET9 version which still works very nicely.
I thought I share it here for others to use: