C# WFA进度条背景色或纹理(非前景)
我在这里或其他指导网站上寻找这个解决方案已经有相当长的时间了。。但许多人只想改变progressbar(随着进度而上升的部分)的前景色 我想,我的小形象可以说明一切: 现在,我正在使用此代码绘制自定义栏,您可以在上面看到。是否可以将后台编辑代码合成到我的构造函数代码中C# WFA进度条背景色或纹理(非前景),c#,.net,winforms,C#,.net,Winforms,我在这里或其他指导网站上寻找这个解决方案已经有相当长的时间了。。但许多人只想改变progressbar(随着进度而上升的部分)的前景色 我想,我的小形象可以说明一切: 现在,我正在使用此代码绘制自定义栏,您可以在上面看到。是否可以将后台编辑代码合成到我的构造函数代码中 public class NewProgressBar : ProgressBar { public NewProgressBar() { this.SetStyle(ControlStyles
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();
}
}
}
}
我在.NET4.5下使用WFA模板
提前感谢这是WinForms控件吗?我认为最好添加您正在使用的GUI工具包的确切名称,以吸引更多专家。一般来说,描述良好的标签会让问题变得更好。如果你想更改背景,为什么不
OnPaintBackground
?嗨,很抱歉丢失了信息(现在添加)是的,这是WFA模板OnPaintBackground-如果我理解正确,正如你所看到的,“如果背景被绘制,会发生什么?”,progressbar是一组部件,如矩形(请参见代码段中的)。我需要找到一段代码,它将重写实际绘制内容的定义。我一直在寻找originall ProgressBar类来编辑它,但我没有发现任何有用的东西:(