This Microsoft Visual C# VALIDATING FORMS exercise is provided to allow potential course delegates to assess their suitability for the Wise Owl VISUAL C# 2005 WINDOWS FORMS course only, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
A full answer to this exercise is provided as part of the training course!
| 1) | Download the files needed to start this exercise: exercise-649.zip (and click here if you experience any problems unzipping this file after downloading it). | ||
| 2) | Add the existing form shown above to your project - you should see this: | ||
Initially there is no validation applied
|
|||
| 3) | Add code to the Validating event of the txtName textbox, so that if the user leaves the length of this textbox as zero you see an error message: | ||
This is what you should see if you leave the name blank
|
|||
| 4) | Now do the same for the txtAge field, but this time check that it is a whole number: | ||
The age must be filled in, and must be a whole number
|
|||
|
|||
| 5) | Finally, add code to the Age field's Validated event so that the age is increased by 10 years after it has been checked: | ||
Acknowledge the fact that no one tells the truth about their age ...
|
|||
| 6) | You should now see that the Validated event fires whether you change the value in their Age text box or not. How might you stop your age increasing by 10 years every time a user leaves the Age text box? | ||
Thank you for showing an interest in this Visual C# 2005 Windows Forms training course! As mentioned above, full answers to this and other exercises are provided on the course. On all Wise Owl scheduled courses delegates can take away these model answers (together with their own efforts!) on a free USB stick.
Recommended sites: C# corner | Computer tutorials | Training classes