One common Windows Application development task is to validate a TextBox or a Windows Control against a certain value, or whether the user has entered a value at all before hitting the submit/Ok button, then display some kind of an error.
The most common GUI technique is to display the error using a MessageBox.Show popup after validating the control, with something like "First Name field is empty! Please enter your First Name". I find these popup boxes in a Windows Application to be annoying... especially when combined with the "bump" wav sound associated with them! So to give my users a friendly app, I thought it would be nice to draw the user's attention to the offending control causing the error, rather than having their attention be on the MessageBox popup with the bump wav sound.
In ASP.NET for example, there are visual validators that you can add to your Web form to indicate missing values in text boxes, or missing check in a check box collection, so why not have a similar thing for a Windows Applications? That's where the "ControlFlasher" object comes in handy
See a Demo app using the ControlFlasher object. (You will need .NET 2.0 installed to run this demo)
How to use the ControlFlasher:
Say you have a Windows Form which Collects First Name, Last Name, Age & Zodiac Sign. You want to ensure when the user clicks on the Submit button that all four fields have been filled, and if not, flash the offending TextBox control to draw user's attention to it: Here is a typical use for the class object:
iNumberOfFlashes = 6;
iFlashCycleDuration = 100;
flashColor = Color.Red;
"Please enter first name"
And the txtbxFirstName control would flash.
There are two ways to use the ControlFlasher:
1. By calling the static factory method:
ControlFlasher Start(Control controlToFlash,
2. By instantiating an object using the constructor:
The ControlFlasher has the following public properties that need to be set:
ControlToFlash: This is the control you want to flash upon a certain condition (Similar to the RequiredFieldValidator ControlToValidate property in ASP.NET)
NumberOfFlashes: How many flash cycles.
FlashCycleDuration: Duration in milliseconds between background color changes (to achieve the flashing effect)
FlashColor: The alternating color during the flash cycle.
Any text message you'd like to display in the Text property of the control being flashed during the entire flash period.
Here is an example operating on a Group Box full of check boxes, none of which got selected by the user:
(!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked && !checkBox4.Checked
&& !checkBox5.Checked && !checkBox6.Checked)
"Select at least One Hobby!");
How does it work?
Once you start the ControlFlasher object, it would start a timer, the timer would alternate the background color of the ControlToFlash as many times as required, waiting for the given period (in milliseconds) between each color change. Once the number of flashes is finished, the timer would stop itself, and the Control properties are restored back to the original.
And that's it... say good bye to the annoying MessageBox popups!
Here is the implementation: