prevent keypress
-
i want to prevet textbox from store characters & numbers in it after some conditional for example if textbox contain "," after 3letters after "," prevent to add any chars to text how?????? ma_refay
Hello, You need to handle the KeyPressed event or override the OnKeyPessed in your TextBoxControl which inherits from TextBox. there you have to compare the "e.KeyChar" with the "," or ".".
if (e.KeyChar == ',')
{
if(this.Text.IndexOf(',') > -1)
{
e.Handled = true; //Will aport the function
}
}Hope that helps! All the best, Martin
-
Hello, You need to handle the KeyPressed event or override the OnKeyPessed in your TextBoxControl which inherits from TextBox. there you have to compare the "e.KeyChar" with the "," or ".".
if (e.KeyChar == ',')
{
if(this.Text.IndexOf(',') > -1)
{
e.Handled = true; //Will aport the function
}
}Hope that helps! All the best, Martin
If you have many different combinations to cater for, then patterns and regular expressions may also help. I think I have once used regular expressions for similar problem in the past...
Ashvin Gunga