Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

A simple question.

The situation is that I need to change the time during run-time. I cant use DateTimePicker as I need to use CustomFormat "hh:mm tt". So, using DateTimePicker to change the time on run-time is not possible.

I do some research and found in forums they suggest to use MaskedTextBox.
I'm not very familiar to use it.

Can you guys help me to explain how to use the MaskedTextBox in TimeFormat. For now it does not a matter whether "hh:mm:ss" or whatever as long I'm able to see the MaskedTextBox works.

Thanks,
Skunkhead :)
Posted

1 solution

Instead of a MaskedTextBox, you can use a DateTimePicker with just the bits you want:

1) Set the CustomFormat property to "hh:mm tt"
2) Set the Format property to Custom (or DateTimePickerFormat.Custom if in code rather than designer)
3) Set the ShowUpDown property to true.

It now shows the time in the format you want, and only the time.
 
Share this answer
 
Comments
skunkhead 10-Feb-11 4:23am    
yeah, that is correct. but can I edit the time on keyboard char press?

I guess DateTimePicker only works for arrows keystroke.
What I want is, something like editable time using keyboard chars.

Thanks.
OriginalGriff 10-Feb-11 4:27am    
Yes. Try it! :laugh:
OriginalGriff 10-Feb-11 4:28am    
What I meant was: "Yes, you can type the time. Try it! :laugh:"
skunkhead 10-Feb-11 4:42am    
yes, you are right!
its working! :crying:
but i have another question, I will open it as another threat. let this one fixed.
JF2015 10-Feb-11 4:48am    
Good and helpful answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900