Basically what I am trying to do is cut down the amount of code in my project.
I have a TextChanged function that is used by all my textboxes. It is called when the user changes anything in any of the text boxes (appoximately 5 per form). Within this _TextChanged function, I am doing additional verification to ensure the user input is not garbage data.
I have to write that if statement (if (textBox1.Text) ) for every single text box. Unless I can somehow pass the variable.family Fire and the textBox1.Text to a function.
like
and call it in my _TextChanged like...
WONTWORK(textBo x1, Variables.famil yFire);
ANY IDEAS?!?!
I have a TextChanged function that is used by all my textboxes. It is called when the user changes anything in any of the text boxes (appoximately 5 per form). Within this _TextChanged function, I am doing additional verification to ensure the user input is not garbage data.
Code:
private void verify_KeyPress(object sender, KeyPressEventArgs e)
{
//ensures values are only numbers (no periods, letters, special char)
if (!((e.KeyChar == 48) || (e.KeyChar == 49) ||
(e.KeyChar == 50) || (e.KeyChar == 51) || (e.KeyChar == 52) ||
(e.KeyChar == 53) || (e.KeyChar == 54) || (e.KeyChar == 55) ||
(e.KeyChar == 56) || (e.KeyChar == 57) || (e.KeyChar == 127) ||
(e.KeyChar == 8)))
e.Handled = true;
}
private void verify_TextChanged(object sender, EventArgs e)
{
textBox1.KeyPress += new KeyPressEventHandler(verify_KeyPress);
[B] if (textBox1.Text != "")
{
int value = int.Parse(textBox1.Text);
if (value >= 0 && value <= 255)
{
Variables.familyFire = value;
textInLabel(value);
}
else
{
Variables.familyFire = 0;
textBox1.Text = "";
}
}[/B] }
like
Code:
public void WONTWORK (object varName, object txtBxName)
{
if (txtBxName.Text != "")
{
int value = int.Parse(txtBxName.Text);
varName = val.ValidateIp(value);
if (varName == 0)
{
txtBxName.Text = "";
}
and call it in my _TextChanged like...
WONTWORK(textBo x1, Variables.famil yFire);
ANY IDEAS?!?!
Comment