In this article, We will create a simple Login Form and we will change the color of the ProgressBar.
If entered password lower then 5 characters, we will set the color of progress bar as red . And if entered chars are between 5 And 8 we will set the color of progressbar is yellow. And once for all if the entered chars are higher then 8 chars, we will set the progress bar color as Green.
Output:
Step 1: Form Design.
Step 2: Program.cs in Solution Explorer.
Step 3: Properties of ProgressBar1
Step 4: C# Code (txtPass_TextChanged)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | private void txtPass_TextChanged(object sender, EventArgs e) { int n = txtPass.Text.Length; if (n > 0 && n < 4) { progressBar1.Value = 1; progressBar1.ForeColor = Color.Red; label1.Text = "weak"; } else if (n >= 4 && n < 8) { progressBar1.Value = 2; progressBar1.ForeColor = Color.Yellow; label1.Text = "medium"; } else if (n >= 8) { progressBar1.Value = 3; progressBar1.ForeColor = Color.Green; label1.Text = "strong"; } else { progressBar1.Value = 0; } } |