I need a textbox to stop receiving values after the comma as soon as I hit 2 houses.
For simplicity, think that the text has a border after the comma, but none before it.
Example:
Enter the number 2.99. Therefore, whenever the user tries to put a value after the 99 it should be locked. However, it should still be possible to delete, delete, and insert values before the comma.
Current code:
public static void verificarCasasPosVirgula(object sender, KeyPressEventArgs e, String Texto)
{
if(Texto.Contains(','))
{
int posicaoVirgula = Texto.IndexOf(',');
String[] array = Texto.Split(',');
if (array[1].Length > 1)
{
if ((e.KeyChar == (char)Keys.Return || e.KeyChar == (char)Keys.Back || e.KeyChar == (char)Keys.Delete))
{
e.Handled = false;
}
else if(posicaoVirgula > -1)
{
e.Handled = true;
}
}
}
}