C#: Validation class for events?

Seite 1 von 1 - Forum: Coding Stuff auf overclockers.at

URL: https://www.overclockers.at/coding-stuff/c_validation_class_for_events_60798/page_1 - zur Vollversion wechseln!


gicio schrieb am 29.12.2002 um 17:56

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




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


Yeahman schrieb am 29.12.2002 um 19:22

I develop .NET Apps for the web, so maybe I'm not the best help, but:

1. -> MSDN? (+Newsgroups)
2. Why do you want to do this?

The Event itself must be catched in the class, and there you put a call to a shared function in the "selfwritten-class"? (maybe I don't see the problem)




overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025