1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| private void TxtDate_KeyPress(object sender, KeyPressEventArgs e)
{
string unTexte = TxtDate.Text;
if (Program.FormatDate(unTexte, e))
{
e.Handled = false;
}
else
{
e.Handled = true;
}
if (unTexte.Length == 10)
{
CultureInfo frFR = new CultureInfo("fr-FR");
DateTime dateValue;
if (!DateTime.TryParseExact(unTexte, "dd/MM/yyyy", frFR, DateTimeStyles.AdjustToUniversal, out dateValue))
{
MessageBox.Show("Format de date incorrect. Veuillez ressaisir svp !");
TxtDate.Text = "";
}
else
{
MessageBox.Show("OK");
}
}
} |
Partager