如何改变进度的C#.NET 3.5的颜色? [英] How to change the color of progressbar in C# .NET 3.5?
本文介绍了如何改变进度的C#.NET 3.5的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要做的两件事情对我的进步吧。
I'd like to do two things on my progress bar.
- 更改绿色变为红色。
- 删除块,使之成为一种颜色。
有关这两件事我不知道如何做到将greatfuly AP preaciated任何信息!
Any information about those two things I wonder how to accomplish will be greatfuly appreaciated!
感谢。
推荐答案
由于previous答案似乎不工作,在视觉样式。您可能需要创建自己的类或延长进度条:
Since the previous answers don't appear to work in with Visual Styles. You'll probably need to create your own class or extend the progress bar:
public class NewProgressBar : ProgressBar
{
public NewProgressBar()
{
this.SetStyle(ControlStyles.UserPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rec = e.ClipRectangle;
rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4;
if(ProgressBarRenderer.IsSupported)
ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle);
rec.Height = rec.Height - 4;
e.Graphics.FillRectangle(Brushes.Red, 2, 2, rec.Width, rec.Height);
}
}
编辑:更新code键使进度条使用视觉样式背景
Updated code to make the progress bar use the visual style for the background
这篇关于如何改变进度的C#.NET 3.5的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文