Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/06/2009, 07:22
maxfereneth
 
Fecha de Ingreso: junio-2009
Mensajes: 10
Antigüedad: 14 años, 11 meses
Puntos: 0
ayuda validacion text box c#

Hola, quiero tener un textbox en c# que acepte numeros con 2 decimales y ademas que acepte el simbolo de % para efectos de calculo de porcentajes, es un textbox para calcular subtotales, ya tengo el codigo para validar los numeros, pero esto me deja con el problema de no poder aceptar el simbolo de %, mi codigo es el siguiente, si me pudieran ayudar se los agradecere mucho <3

void textBoxDescuento_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 8)
{
e.Handled = false;
return;
}


bool IsDec = false;
int nroDec = 0;

for (int i = 0; i < textBoxDescuento.Text.Length; i++)
{
if (textBoxDescuento.Text[i] == '.')
IsDec = true;

if (IsDec && nroDec++ >= 2)
{
e.Handled = true;
return;
}


}

if (e.KeyChar >= 48 && e.KeyChar <= 57)
e.Handled = false;
else if (e.KeyChar == 46)
e.Handled = (IsDec) ? true : false;
else
e.Handled = true;

}