Auto put / in date fields

  • Thread starter Thread starter Ricardo
  • Start date Start date
R

Ricardo

How di I do to when the user is typing a date in a textbox when he type the
2 days numbers, the next caracter ( the / caracter) appears???

[]s...
 
Hi Ricardo,

You would have to do it the hard way.
This piece of code will accomplish what you need but it does not check for
anything out of the ordinary (like the user edits the text causing / to
appear when you don't want it etc) It uses the TextChanged event to
detect the number of characters entered and inserts / when needed.

private void textBox1_TextChanged(object sender, EventArgs e)
{
if(t.TextLength == 2 || t.TextLength == 5)
t.Text += "/";
t.SelectionStart = t.TextLength;
}
 
Back
Top