How to enter "Time"-Values?

  • Thread starter Thread starter Boris Nienke
  • Start date Start date
B

Boris Nienke

Hi,

in an other field i would like to enter just valid Time-Values
("99:99").

Is there a Time-Edit-Field available? How have you solved this?

Boris
 
Boris,

I don't worry about Time Edit Field - I just validate it as in the
following. Maybe this would suit you.

private void txtTime_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
TimeSpan ts;
if ( txtTime.Text != string.Empty )
{
try
{
ts = TimeSpan.Parse(txtTime.Text);
}
catch
{
e.Cancel = true;
MessageBox.Show("Not a valid time", "Error");
txtTime.Focus();
txtTime.Text = string.Empty;
txtTime.Select(0, txtTime.Text.Length);
}
}
}
 
Hey, thank you very much!

It's not the best solution (a mask-field or something would be better)
but this works great.

I've looked at the MS-Calendar and it seems, that MS is doing nearly the
same ;-)

thanks

Boris
 
Back
Top