September 17th, 2009 by dmedellin Leave a reply »

hola buenas tarde, me encuentro descubriendo el mundo de WPF, la vdd he debatido con migo mismo acerca de esta nueva forma de manejar la interfaz de nuestras aplicaciones y no llego a conclusion alguna… creo que solo continuo en esto porque es nuevo para mi y me emociona.

ahora si aqui les dejo una forma “casera” de como hacer un filteredTextBox
private void txtFecha_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space) e.Handled = true;
if (e.Key == Key.Tab || e.Key == Key.Enter)
{
if (txtFecha.Text.Length != 10)
{
txtFecha.Focus();
return;
}
if (Convert.ToInt16(txtFecha.Text.Substring(3, 2)) > 12 || Convert.ToInt16(txtFecha.Text.Substring(3, 2)) <>

{
MessageBox.Show(“mes incorrecto”, “aviso”);
txtFecha.Focus();
return;
}
if (Convert.ToInt16(txtFecha.Text.Substring(0, 2)) >
DateTime.DaysInMonth(Convert.ToInt16(txtFecha.Text.Substring(6, 4)), Convert.ToInt16(txtFecha.Text.Substring(3, 2))))
{
MessageBox.Show(“dia incorrecto”, “aviso”);
txtFecha.Focus();
}
return;
}
if (txtFecha.Text.Length != 2 && txtFecha.Text.Length != 5)
{
if (!(e.Key == Key.D0 || e.Key == Key.D1 || e.Key == Key.D2 || e.Key == Key.D3 || e.Key == Key.D4 || e.Key == Key.D5 || e.Key == Key.D6
|| e.Key == Key.D7 || e.Key == Key.D8 || e.Key == Key.D9 || e.Key == Key.NumPad0 || e.Key == Key.NumPad1 ||
e.Key == Key.NumPad2 || e.Key == Key.NumPad3 || e.Key == Key.NumPad4 || e.Key == Key.NumPad5 || e.Key == Key.NumPad6
|| e.Key == Key.NumPad7 || e.Key == Key.NumPad8 || e.Key == Key.NumPad9))
e.Handled = true;
}
else
if (!(e.Key == Key.Subtract || e.Key == Key.Divide || e.Key == Key.OemPeriod || e.Key == Key.Decimal))
e.Handled = true;
}
talvez no sea la mas optima jejeje pero me saco del apuro, espero les ayude tantio!!! por favor den mas opciones
Compartir en:
Advertisement

Leave a Reply