Hi All,
I have a method to tell me if a user has entered an invalid key during a textbox's key press event.I would like to use this method in different classes that are all part of the same name space and class library. [Here comes the DUH part] The only way I have been able to call the method, is to create an object of the class that the method is in and then call the method. Is there a way to call the method directly if it is in the same namespace as the code without having to create the object like shown below?Code:private bool InvalidCharacters(System.Windows.Forms.KeyPressEventArgs e) { bool returnValue = false; if(e.KeyChar == '\''){returnValue = true;} else if(e.KeyChar == '`'){returnValue = true;} else if(e.KeyChar == ','){returnValue = true;} return returnValue; }I hope that makes sense.Code:private void txtUserOSName_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if(InvalidCharacters(e)){e.Handled = true;} }
Thanks Steve




Reply With Quote