[C#] Validation class for events?

csharp United States
  • 18 years ago

    Hi,


    I develop an application that have 20 windows forms with many TextBoxes.
    All TextBoxes have the same validation...
    I write in all classes the same validation like that:




    [CODE]        
           //if the user press a key down at txtDisplacement we check which one was pressed down
           #region KeyDownInTxtDisplacement code
           private void KeyDownInTxtDisplacement(object sender, System.Windows.Forms.KeyEventArgs e)
           {
               CheckWhichKeyDown(e);
           }
           #endregion




           //if the user press a key down at txtModel we check which one was pressed down
           #region KeyDownInTxtModel code
           private void KeyDownInTxtModel(object sender, System.Windows.Forms.KeyEventArgs e)
           {
               CheckWhichKeyDown(e);
           }
           #endregion




           //we check which key is pressed
           //if key Enter or Return or Tab is pressed
           //we go throw DoWhenOneTextBoxIsMarkedRed()
           #region CheckWhichKeyDown code
           private void CheckWhichKeyDown(System.Windows.Forms.KeyEventArgs e)
           {
               if(e.KeyCode==Keys.Enter || e.KeyCode==Keys.Return || e.KeyCode==Keys.Tab)
               {
                   ValidateThis();
               }        
           }
           #endregion




           //when special key is press we enable the button
           #region ValidateThis code
           private void ValidateThis()
           {
               cmdAddToDataBase.Enabled = true;
           }
           #endregion
    [/CODE]





    CheckWhichKeyDown and ValidateThis should be in one validation class.
    How I can write a validation class that validate ALL TextBoxes from all classes.
    Any ideas?
    Or do you know some sample validation classes available on www?



    gicio

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The difference between theory and practice is smaller in theory than in practice.”