继承ProgressBar publicenumTextPosition{Left,Right,Center,Sliding,None}publicclassBzProgressBar:ProgressBar{privateColorchannelColorColor。LightSteelBlue;privateColorsliderColorColor。RoyalBlue;privateColorforeBackColorColor。RoyalBlue;privateintchannelHeight6;privateintsliderHeight6;privateTextPositionshowValueTextPosition。Right;publicBzProgressBar(){this。SetStyle(ControlStyles。OptimizedDoubleBuffer,true);this。SetStyle(ControlStyles。UserPaint,true);this。ForeColorColor。White;}〔Category(BZAdvance)〕publicColorChannelColor{get{returnchannelColor;}set{channelColorvalue;this。Invalidate();}}〔Category(BZAdvance)〕publicColorSliderColor{get{returnsliderColor;}set{sliderColorvalue;this。Invalidate();}}〔Category(BZAdvance)〕publicColorForeBackColor{get{returnforeBackColor;}set{foreBackColorvalue;this。Invalidate();}}〔Category(BZAdvance)〕publicintChannelHeight{get{returnchannelHeight;}set{channelHeightvalue;this。Invalidate();}}〔Category(BZAdvance)〕publicintSliderHeight{get{returnsliderHeight;}set{sliderHeightvalue;this。Invalidate();}}〔Category(BZAdvance)〕publicTextPositionShowValue{get{returnshowValue;}set{showValuevalue;this。Invalidate();}}〔Category(BZAdvance)〕〔Browsable(true)〕〔EditorBrowsable(EditorBrowsableState。Always)〕publicoverrideFontFont{get{returnbase。Font;}set{base。Fontvalue;}}〔Category(BZAdvance)〕publicoverrideColorForeColor{get{returnbase。ForeColor;}set{base。ForeColorvalue;}}protectedoverridevoidOnPaint(PaintEventArgse){Graphicsgraphicse。Graphics;RectanglerectChannelnewRectangle(0,0,this。Width,channelHeight);using(varbrushChannelnewSolidBrush(channelColor)){if(channelHeightsliderHeight){rectChannel。Ythis。HeightchannelHeight;}else{rectChannel。Ythis。Height((channelHeightsliderHeight)2);}graphics。Clear(this。Parent。BackColor);graphics。FillRectangle(brushChannel,rectChannel);}doublescaleFactor(((double)this。Valuethis。Minimum))(((double)this。Maximumthis。Minimum));intsliderWidth(int)(this。WidthscaleFactor);RectanglerectSlidernewRectangle(0,0,sliderWidth,SliderHeight);using(varbrushSlidernewSolidBrush(sliderColor)){if(SliderHeightchannelHeight){rectSlider。Ythis。HeightsliderHeight;}else{rectSlider。Ythis。Height(sliderHeightchannelHeight)2;}if(sliderWidth1){graphics。FillRectangle(brushSlider,rectSlider);}if(ShowValue!TextPosition。None){DrawValueText(graphics,sliderWidth,rectSlider);}}base。OnPaint(e);}summary显示进度百分比summaryparamnamegraphicsparamparamnamesliderWidthparamparamnamerectSliderparamprivatevoidDrawValueText(Graphicsgraphics,intsliderWidth,RectanglerectSlider){stringtextthis。Value。ToString();vartextSizeTextRenderer。MeasureText(text,this。Font);varrectTextnewRectangle(0,0,textSize。Width,textSize。Height2);using(varbrushTextnewSolidBrush(this。ForeColor))using(varbrushTextBacknewSolidBrush(this。ForeBackColor))using(vartextFormatnewStringFormat()){switch(showValue){caseTextPosition。Left:rectText。X0;textFormat。AlignmentStringAlignment。Near;break;caseTextPosition。Right:rectText。Xthis。WidthtextSize。Width;textFormat。AlignmentStringAlignment。Far;break;caseTextPosition。Center:rectText。X(this。WidthtextSize。Width)2;textFormat。AlignmentStringAlignment。Center;break;caseTextPosition。Sliding:rectText。XsliderWidthtextSize。Width;textFormat。AlignmentStringAlignment。Center;using(varbrushClearnewSolidBrush(this。Parent。BackColor)){varrectrectSlider;rect。YrectText。Y;rect。Heightrect。Height;graphics。FillRectangle(brushClear,rect);}break;default:break;}graphics。FillRectangle(brushTextBack,rectText);graphics。DrawString(text,this。Font,brushText,rectText,textFormat);}}}