C#进度条改变颜色 [英] C# progress bar change color
问题描述
我正在尝试更改我的进度条的颜色,我使用它作为密码强度验证器。例如,如果所需的密码是弱的,进度条将变成黄色,如果中,然后绿色。强,橙。很强,红色。这就是这样。这里是我的密码强度验证程序的代码:
I am trying to change the color of my progress bar, I'm using it as a password strength validator. For example, if the desired password is weak, the progress bar will turn yellow, if medium, then green. Strong, orange. Very strong, red. It's just something like that. Here's my code for the password strength validator:
using System.Text.RegularExpressions;
using System.Drawing;
using System.Drawing.Drawing2D;
var PassChar = txtPass.Text;
if (txtPass.Text.Length < 4)
pgbPass.ForeColor = Color.White;
if (txtPass.Text.Length >= 6)
pgbPass.ForeColor = Color.Yellow;
if (txtPass.Text.Length >= 12)
pgbPass.ForeColor = Color.YellowGreen;
if (Regex.IsMatch(PassChar, @"\d+"))
pgbPass.ForeColor = Color.Green;
if (Regex.IsMatch(PassChar, @"[a-z]") && Regex.IsMatch(PassChar, @"[A-Z]"))
pgbPass.ForeColor = Color.Orange;
if (Regex.IsMatch(PassChar, @"[!@#\$%\^&\*\?_~\-\(\);\.\+:]+"))
pgbPass.ForeColor = Color.Red;
pgbPass.ForeColor = Color.ColorHere
似乎没有工作。任何帮助?感谢。
The pgbPass.ForeColor = Color.ColorHere
doesn't seem to be working. Any help? Thanks.
推荐答案
进度条颜色不能在c#中更改,除非可视样式已禁用。颜色将观察不到颜色变化,因为进度条将占据当前操作系统的视觉风格。您可以选择禁用整个应用程序的视觉风格。要做到这一点,去程序的开始类,并删除这行代码
The Progress Bar Color cannot be changed in c# unless the the Visual Styles are Disabled.Although the IDE Offers to change the Color you will observe no color change as the progress bar will take up the visual style of the current operating system.You can opt to disable the visual style for your whole application.To do this go to the starting class of the program and remove this line from the code
Application.EnableVisualStyles();
或者使用一些自定义进度条控件如下
http://www.codeproject.com/KB/cpp/colorprogressbar.aspx
or use some custom progress bar control like this http://www.codeproject.com/KB/cpp/colorprogressbar.aspx
这篇关于C#进度条改变颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!