C
Christian Blackburn
Hi Gang,
I have written a product registration screen that has three text
boxes. They take 4 numbers each (I know that's too few, but I'm not
the originator of this code). In any event I want them to only allow
numbers as inputs. I would like to have the same event fire when
pressing keys in each of the text boxes:
this.txtCode1.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(txtCode_KeyPress);
this.txtCode2.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(txtCode_KeyPress);
this.txtCode3.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(txtCode_KeyPress);
private void txtCode_KeyPress(object sender, KeyEventArgs e)
{
//if the user typed in a number then...
if (e.KeyValue > 47 && e.KeyValue < 58)
{
e.Handled = true;
}
}
I get the same error message 3 times (one for each textbox):
No overload for 'txtCode_KeyPress' matches delegate
'System.Windows.Forms.KeyPressEventHandler'
No overload for 'txtCode_KeyPress' matches delegate
'System.Windows.Forms.KeyPressEventHandler'
No overload for 'txtCode_KeyPress' matches delegate
'System.Windows.Forms.KeyPressEventHandler'
I suspect I'm just missing a keyword somewhere?
Thanks,
Christian
I have written a product registration screen that has three text
boxes. They take 4 numbers each (I know that's too few, but I'm not
the originator of this code). In any event I want them to only allow
numbers as inputs. I would like to have the same event fire when
pressing keys in each of the text boxes:
this.txtCode1.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(txtCode_KeyPress);
this.txtCode2.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(txtCode_KeyPress);
this.txtCode3.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(txtCode_KeyPress);
private void txtCode_KeyPress(object sender, KeyEventArgs e)
{
//if the user typed in a number then...
if (e.KeyValue > 47 && e.KeyValue < 58)
{
e.Handled = true;
}
}
I get the same error message 3 times (one for each textbox):
No overload for 'txtCode_KeyPress' matches delegate
'System.Windows.Forms.KeyPressEventHandler'
No overload for 'txtCode_KeyPress' matches delegate
'System.Windows.Forms.KeyPressEventHandler'
No overload for 'txtCode_KeyPress' matches delegate
'System.Windows.Forms.KeyPressEventHandler'
I suspect I'm just missing a keyword somewhere?
Thanks,
Christian