4
I need a textbox to stop receiving values after the comma, once it reaches 2 houses.
To simplify, think that the text has limit after the comma, but none before it.
Example:
Type the number 2.99. So, 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;
}
}
}
}
What kind of application is?
– Marco Souza
Desktop, made in C#
– Rafael
windows Forms ?
– Marco Souza
This, done with windows Forms.
– Rafael