We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

IMMEDIATE HELP WANTED: Time values in TextBox

Thread ID:





72825 Apr 8,2008 06:17 AM UTC Apr 8,2008 10:47 AM UTC WinForms 1
Tags: Tools
Asked On April 8, 2008 06:17 AM UTC


I have a textbox which is to be entered time value in HH:mm format. It contains no of hours and mins.
56:45[Fifty six hours and fourty five mins]

What is the best way to do..?
problem stop the entering invalid minutes.

Administrator [Syncfusion]
Replied On April 8, 2008 10:47 AM UTC

Hi Apwickrama,

Thank you for your interest in Syncfusion Products.

To restrict the user to display valid time alone in the TextBoxExt, please refer the following code snippet for more details which performs the check when typing the Time and pressing Enter key:

private void textBoxExt1_KeyDown(object sender, KeyEventArgs e)
if (e.KeyCode == Keys.Enter)
string str = this.textBoxExt1.Text;
int ind = str.IndexOf(":");
string hr = str.Substring(0, ind);
string min = str.Substring(ind + 1, 2);
int hour = Convert.ToInt32(hr);
int minutes = Convert.ToInt32(min);
if (hour > 23 || hour < 0 || minutes < 0 || minutes > 59)
MessageBox.Show("Invalid date and time");
this.textBoxExt1.Text = "";
MessageBox.Show("Valid Time");

Please let me know if any concerns.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon