Foros del Web » Programación para mayores de 30 ;) » .NET »

Formato de fecha en textbox

Estas en el tema de Formato de fecha en textbox en el foro de .NET en Foros del Web. Hola Foro. Pues veran tengo este codigo el cual conforme voy tecleando el una caja de texto le voy dando el formato de la fecha ...
  #1 (permalink)  
Antiguo 02/05/2005, 18:12
Avatar de grisel  
Fecha de Ingreso: diciembre-2004
Ubicación: Mexico
Mensajes: 215
Antigüedad: 19 años, 4 meses
Puntos: 0
Formato de fecha en textbox

Hola Foro.

Pues veran tengo este codigo el cual conforme voy tecleando el una caja de texto le voy dando el formato de la fecha solo que es un formato para fechas en donde primero se coloca el mes es decir 05/23/2005 y yo necesito el siguiente formato 23/05/2005
he tratado de ver por varia formas y nada si alguien me pudiera ayudar o decirme alguna manera de no complicarmela tanto.

mil gracias por su atencion.
saludos y bye


private void MaskDate(KeyPressEventArgs e)
{
int len = this.Text.Length;
int indx = this.Text.LastIndexOf("/")
// if test is highlighted reset vars
if(this.SelectedText == this.Text)
{
indx=-1;
digitPos=0;
DelimitNumber=0;
this.Text=null;
}
if(Char.IsDigit(e.KeyChar) || e.KeyChar == '/' || e.KeyChar == 8)
{
string tmp = this.Text;
if (e.KeyChar != 8)
{
if (e.KeyChar != '/' )
{
if(indx > 0)
digitPos = len-indx;
else
digitPos++;
if (digitPos == 3 && DelimitNumber < 2)
{
if (e.KeyChar != '/')
{
DelimitNumber++;
this.AppendText("/");
}
}
errorProvider1.SetError(this, "");
if( (digitPos == 2 || (Int32.Parse(e.KeyChar.ToString())>1 && DelimitNumber ==0) ))
{
string tmp2;
if(indx == -1)
tmp2= e.KeyChar.ToString();
else
tmp2 = this.Text.Substring(indx+1)+e.KeyChar.ToString();

if(DelimitNumber < 2)
{
if(digitPos==1) this.AppendText("0");
this.AppendText(e.KeyChar.ToString());
if(indx <0)
{
if(Int32.Parse(this.Text)> 12) // check validation
{
string str;
str = this.Text.Insert(0, "0");
if(Int32.Parse(this.Text)>13)
{
this.Text =str.Insert(2, "/0");
DelimitNumber++;
this.AppendText("/");
}
else
{
this.Text =str.Insert(2, "/");
this.AppendText("");
}
DelimitNumber++;
} else
{
this.AppendText("/");
DelimitNumber++;
}
e.Handled=true;
}
else
{
if( DelimitNumber == 1)
{
int m = Int32.Parse(this.Text.Substring(0,indx));
if(!CheckDayOfMonth(m,Int32.Parse(tmp2)))
errorProvider1.SetError(this, "Asegurese que el mes tenga ese día");
else
{
this.AppendText("/");
DelimitNumber++;
e.Handled=true;
}
}
}
}
}
else if(digitPos == 1 && Int32.Parse(e.KeyChar.ToString())>3 && DelimitNumber<2)
{
if(digitPos==1) this.AppendText("0");
this.AppendText(e.KeyChar.ToString());
this.AppendText("/");
DelimitNumber++;
e.Handled = true;
}
else
{
if(digitPos == 1 && DelimitNumber==2 && e.KeyChar > '2')
errorProvider1.SetError(this, "El año debe empezar con 1 o 2");
}
}
else
{
DelimitNumber++;
string tmp3;
if(indx == -1)
tmp3 = this.Text.Substring(indx+1);
else
tmp3 = this.Text;
if(digitPos == 1)
{
this.Text = tmp3.Insert(indx+1,"0");;
this.AppendText("/");
e.Handled = true;
}
}
}
else
{
e.Handled = false;
if((len-indx) == 1)
{
DelimitNumber--;
if (indx > -1 )
digitPos = 2;
else
digitPos--;
}
else
{
if(indx > -1)
digitPos=len-indx-1;
else
digitPos=len-1;
}
}
}
else
{
e.Handled = true;
errorProvider1.SetError(this, "Formato de fecha");
}
}
__________________
grissss :Zzz:
  #2 (permalink)  
Antiguo 03/05/2005, 08:49
Avatar de RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 22 años, 2 meses
Puntos: 50
Aqui hay un control que te puede servir:

http://www.codeproject.com/cs/miscctrl/maskedcsedit.asp

Compilalo, y luego lo agregas a tu toolbox para que veas su funcionamiento

Ya sería cosa de que le hagas las adaptaciones que necesites.. pero verás que no es dificil.

Salu2
__________________
Nadie roba nada ya que en la vida todo se paga . . .

Exentrit - Soluciones SharePoint & Net
  #3 (permalink)  
Antiguo 03/05/2005, 10:26
Avatar de RicaJ0625  
Fecha de Ingreso: noviembre-2004
Ubicación: La Chorrera, Panamá
Mensajes: 86
Antigüedad: 19 años, 5 meses
Puntos: 0
RJS.PopCalendar 3.7 (3.1.1)

Tengo este Control que es un calendario selector de fecha que creo que te puede servir. Ademas te deja escribir en el textbox y el calendario valida la fecha.

http://code.msdn.microsoft.com/RJSPopCalendar

Y es gratis.

Disculpen esto no es para windows form. Es para Web Form.

Última edición por RicaJ0625; 23/02/2008 a las 11:16
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:27.