我一直在寻找这个解决方案很长一段时间,在这里,或其他指导网站..但是很多人想要改变进度条的前景色(随着进度而上升的部分)
我想,我的小图片可以说出一切:
http://screenshot.cz/WT5KO/progbar.png
现在,我正在使用此代码绘制自定义栏,您可以在上面看到。是否可以将后台编辑代码组合到我的构造函数代码中?
public class NewProgressBar : ProgressBar
{
public NewProgressBar()
{
this.SetStyle(ControlStyles.UserPaint, true);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
// None... Helps control the flicker.
}
protected override void OnPaint(PaintEventArgs e)
{
const int inset = 0; // A single inset value to control teh sizing of the inner rect.
using (Image offscreenImage = new Bitmap(this.Width, this.Height))
{
using (Graphics offscreen = Graphics.FromImage(offscreenImage))
{
Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
if (ProgressBarRenderer.IsSupported)
ProgressBarRenderer.DrawHorizontalBar(offscreen, rect);
rect.Inflate(new Size(-inset, -inset)); // Deflate inner rect.
rect.Width = (int)(rect.Width * ((double)this.Value / this.Maximum));
if (rect.Width == 0) rect.Width = 1; // Can't draw rec with width of 0.
TextureBrush mybrush = new TextureBrush(Properties.Resources.loading);
LinearGradientBrush brush = new LinearGradientBrush(rect, Color.DarkGoldenrod, Color.Gold, LinearGradientMode.Vertical);
offscreen.FillRectangle(mybrush, inset, inset, rect.Width, rect.Height);
e.Graphics.DrawImage(offscreenImage, 0, 0);
offscreenImage.Dispose();
}
}
}
}
我在.NET 4.5下使用WFA模板
提前致谢