Passing Current Component to a function
Hello
I am writting a simple app and I have run into a problem that I can't google the answer to. I am probably asking wrong, dunno. I have multiple textboxes on a tabbed component. I am using the validating command to make sure the user inputted a value and if not input one. There are lots of these text boxes and they all have the same event code that differ only by the component using it. but I can not figure out how to pass a component with functionality to a module so I can reuse the same code and cut down on my repitition. Any advice? I know its simple but with out a data type I can only think of overly complex things. THanks for anything
Posted Apr 1, 2009, 4:41 PM
this.myTextBox.Validating = new System.CancelEventHandler(myTextBox_Validating);
private void myTextBox_Validating(object sender, CancelEventArgs e)
{
// call the validating function in here...
ValidateTextBoxInput(this.myTextBox);
}
Its easiest if in the designer you select the text box, then go to the Properties pane and click the little lightning bolt at the top and scroll down and double click the Validating event and it will attach the event in the Designer.cs code file and create the event handler in your forms code behind. From there you just do the validating.
JonathanPosted Mar 31, 2009, 10:42 AM
Posted Mar 31, 2009, 10:22 AM
private void DoSomethingWithTextBox(TextBox textBox)
{
// Alter the TextBox object here, its passed by reference automatically so
// if you change it here it will update the orignal one.
}