steve65
Jun 14th, 2006, 01:38 PM
Hi All,
I have a method to tell me if a user has entered an invalid key during a textbox's key press event.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 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?private void txtUserOSName_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(InvalidCharacters(e)){e.Handled = true;}
}I hope that makes sense.
Thanks Steve
I have a method to tell me if a user has entered an invalid key during a textbox's key press event.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 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?private void txtUserOSName_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(InvalidCharacters(e)){e.Handled = true;}
}I hope that makes sense.
Thanks Steve